@@ -907,60 +907,56 @@ await expect(elem).toHaveElementClass(/Container/i)
907907In addition to the WebdriverIO matchers, ` expect-webdriverio ` also provides basic matchers from Jest's [ expect] ( https://jestjs.io/docs/expect ) library.
908908
909909``` ts
910- describe (' Expect matchers' , () => {
911- test (' Basic matchers' , async () => {
912- // Equality
913- expect (2 + 2 ).toBe (4 );
914- expect ({a: 1 }).toEqual ({a: 1 });
915- expect ([1 , 2 , 3 ]).toStrictEqual ([1 , 2 , 3 ]);
916- expect (2 + 2 ).not .toBe (5 );
917-
918- // Truthiness
919- expect (null ).toBeNull ();
920- expect (undefined ).toBeUndefined ();
921- expect (0 ).toBeFalsy ();
922- expect (1 ).toBeTruthy ();
923- expect (NaN ).toBeNaN ();
924-
925- // Numbers
926- expect (4 ).toBeGreaterThan (3 );
927- expect (4 ).toBeGreaterThanOrEqual (4 );
928- expect (4 ).toBeLessThan (5 );
929- expect (4 ).toBeLessThanOrEqual (4 );
930- expect (0.2 + 0.1 ).toBeCloseTo (0.3 , 5 );
931-
932- // Strings
933- expect (' team' ).toMatch (/ team/ );
934- expect (' Christoph' ).toContain (' stop' );
935-
936- // Arrays and iterables
937- expect ([1 , 2 , 3 ]).toContain (2 );
938- expect ([{a: 1 }, {b: 2 }]).toContainEqual ({a: 1 });
939- expect ([1 , 2 , 3 ]).toHaveLength (3 );
940-
941- // Objects
942- expect ({a: 1 , b: 2 }).toHaveProperty (' a' );
943- expect ({a: {b: 2 }}).toHaveProperty (' a.b' , 2 );
944-
945- // Errors
946- expect (() => { throw new Error (' error!' ) }).toThrow (' error!' );
947- expect (() => { throw new TypeError (' wrong type' ) }).toThrow (TypeError );
948-
949- // Asymmetric matchers
950- expect ({foo: ' bar' , baz: 1 }).toEqual (expect .objectContaining ({foo: expect .any (String )}));
951- expect ([1 , 2 , 3 ]).toEqual (expect .arrayContaining ([2 ]));
952- expect (' abc' ).toEqual (expect .stringContaining (' b' ));
953- expect (' abc' ).toEqual (expect .stringMatching (/ b/ ));
954- expect (123 ).toEqual (expect .any (Number ));
955-
956- // Others
957- expect (new Set ([1 , 2 , 3 ])).toContain (2 );
958-
959- // .resolves / .rejects (async)
960- await expect (Promise .resolve (42 )).resolves .toBe (42 );
961- await expect (Promise .reject (new Error (' fail' ))).rejects .toThrow (' fail' );
962- });
963- });
910+ // Equality
911+ expect (2 + 2 ).toBe (4 );
912+ expect ({a: 1 }).toEqual ({a: 1 });
913+ expect ([1 , 2 , 3 ]).toStrictEqual ([1 , 2 , 3 ]);
914+ expect (2 + 2 ).not .toBe (5 );
915+
916+ // Truthiness
917+ expect (null ).toBeNull ();
918+ expect (undefined ).toBeUndefined ();
919+ expect (0 ).toBeFalsy ();
920+ expect (1 ).toBeTruthy ();
921+ expect (NaN ).toBeNaN ();
922+
923+ // Numbers
924+ expect (4 ).toBeGreaterThan (3 );
925+ expect (4 ).toBeGreaterThanOrEqual (4 );
926+ expect (4 ).toBeLessThan (5 );
927+ expect (4 ).toBeLessThanOrEqual (4 );
928+ expect (0.2 + 0.1 ).toBeCloseTo (0.3 , 5 );
929+
930+ // Strings
931+ expect (' team' ).toMatch (/ team/ );
932+ expect (' Christoph' ).toContain (' stop' );
933+
934+ // Arrays and iterables
935+ expect ([1 , 2 , 3 ]).toContain (2 );
936+ expect ([{a: 1 }, {b: 2 }]).toContainEqual ({a: 1 });
937+ expect ([1 , 2 , 3 ]).toHaveLength (3 );
938+
939+ // Objects
940+ expect ({a: 1 , b: 2 }).toHaveProperty (' a' );
941+ expect ({a: {b: 2 }}).toHaveProperty (' a.b' , 2 );
942+
943+ // Errors
944+ expect (() => { throw new Error (' error!' ) }).toThrow (' error!' );
945+ expect (() => { throw new TypeError (' wrong type' ) }).toThrow (TypeError );
946+
947+ // Asymmetric matchers
948+ expect ({foo: ' bar' , baz: 1 }).toEqual (expect .objectContaining ({foo: expect .any (String )}));
949+ expect ([1 , 2 , 3 ]).toEqual (expect .arrayContaining ([2 ]));
950+ expect (' abc' ).toEqual (expect .stringContaining (' b' ));
951+ expect (' abc' ).toEqual (expect .stringMatching (/ b/ ));
952+ expect (123 ).toEqual (expect .any (Number ));
953+
954+ // Others
955+ expect (new Set ([1 , 2 , 3 ])).toContain (2 );
956+
957+ // .resolves / .rejects (async)
958+ await expect (Promise .resolve (42 )).resolves .toBe (42 );
959+ await expect (Promise .reject (new Error (' fail' ))).rejects .toThrow (' fail' );
964960```
965961
966962### Jasmine
@@ -1013,7 +1009,7 @@ await expect(browser).toHaveTitle(expect.not.stringContaining('some title'))
10131009Under ` @wdio/jasmine-framework ` , Jasmine asymmetric matchers now works with WebdriverIO matchers and the global import
10141010
10151011``` ts
1016- // Jasmine stringContaining works just lik expect one's
1012+ // Jasmine stringContaining works just like expect one's
10171013await expect (browser ).toHaveTitle (jasmine .stringContaining (' some title' ))
10181014await expect (browser ).toHaveTitle (expect .stringContaining (' some title' ))
10191015```
0 commit comments