twd-js 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
1
  import { AnyAssertion } from '../twd-types';
2
- export declare const runAssertion: (el: Element, name: AnyAssertion, ...args: any[]) => void;
2
+ export declare const runAssertion: (el: Element, name: AnyAssertion, ...args: any[]) => string;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * All supported assertion names for the `should` function in url command
3
+ *
4
+ * @example
5
+ * twd.url().should("contain.url", "/new-page");
6
+ * twd.url().should("eq", "http://localhost:3000/new-page");
7
+ */
8
+ export type URLAssertionName = "eq" | "contain.url";
9
+ /**
10
+ * Negatable assertion names (e.g., 'not.have.text').
11
+ */
12
+ export type Negatable<T extends string> = T | `not.${T}`;
13
+ /**
14
+ * All assertion names, including negated ones.
15
+ */
16
+ export type AnyURLAssertion = Negatable<URLAssertionName>;
17
+ export type URLCommandAPI = {
18
+ location: Location;
19
+ should: (name: AnyURLAssertion, value: string) => URLCommandAPI | string;
20
+ };
21
+ /**
22
+ * Argument types for each assertion.
23
+ */
24
+ export type URLAssertionArgs = {
25
+ (name: "contain.url", urlPart: string): URLCommandAPI;
26
+ (name: "not.contain.url", urlPart: string): URLCommandAPI;
27
+ };
28
+ /**
29
+ * URL command for assertions on the current URL.
30
+ * @returns URLCommandAPI
31
+ */
32
+ declare const urlCommand: () => URLCommandAPI;
33
+ export default urlCommand;
@@ -50,16 +50,25 @@ export type ArgsFor<A extends AnyAssertion> = A extends `not.${infer Base extend
50
50
  */
51
51
  export type ShouldFn = {
52
52
  (name: "have.text", expected: string): TWDElemAPI;
53
+ (name: "not.have.text", expected: string): TWDElemAPI;
53
54
  (name: "contain.text", expected: string): TWDElemAPI;
55
+ (name: "not.contain.text", expected: string): TWDElemAPI;
54
56
  (name: "be.empty"): TWDElemAPI;
57
+ (name: "not.be.empty"): TWDElemAPI;
55
58
  (name: "have.attr", attr: string, value: string): TWDElemAPI;
59
+ (name: "not.have.attr", attr: string, value: string): TWDElemAPI;
56
60
  (name: "have.value", value: string): TWDElemAPI;
61
+ (name: "not.have.value", value: string): TWDElemAPI;
57
62
  (name: "be.disabled"): TWDElemAPI;
63
+ (name: "not.be.disabled"): TWDElemAPI;
58
64
  (name: "be.enabled"): TWDElemAPI;
65
+ (name: "not.be.enabled"): TWDElemAPI;
59
66
  (name: "be.checked"): TWDElemAPI;
60
67
  (name: "not.be.checked"): TWDElemAPI;
61
68
  (name: "be.selected"): TWDElemAPI;
69
+ (name: "not.be.selected"): TWDElemAPI;
62
70
  (name: "be.focused"): TWDElemAPI;
71
+ (name: "not.be.focused"): TWDElemAPI;
63
72
  (name: "be.visible"): TWDElemAPI;
64
73
  (name: "not.be.visible"): TWDElemAPI;
65
74
  (name: "have.class", className: string): TWDElemAPI;
@@ -122,7 +131,7 @@ export interface TWDElemAPI {
122
131
  text: () => string;
123
132
  /**
124
133
  * Asserts something about the element.
125
- * @param anyAssertion The assertion to run.
134
+ * @param name The name of the assertion.
126
135
  * @param args Arguments for the assertion.
127
136
  * @returns The same API for chaining.
128
137
  *
package/dist/twd.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Options, Rule } from './commands/mockResponses';
2
2
  import { TWDElemAPI } from './twd-types';
3
+ import { URLCommandAPI } from './commands/url';
3
4
  /**
4
5
  * Stores the function to run before each test.
5
6
  */
@@ -95,6 +96,17 @@ interface TWDAPI {
95
96
  * ```
96
97
  */
97
98
  waitFor: (alias: string) => Promise<Rule>;
99
+ /**
100
+ * URL-related assertions.
101
+ *
102
+ * @example
103
+ * ```ts
104
+ * twd.url().should("eq", "http://localhost:3000/contact");
105
+ * twd.url().should("contain.url", "/contact");
106
+ *
107
+ * ```
108
+ */
109
+ url: () => URLCommandAPI;
98
110
  }
99
111
  /**
100
112
  * Mini Cypress-style helpers for DOM testing.