expect.stringMatching() matches a received string that in turn matches the expected pattern. Use this method inside expect(value).toEqual(expected) to perform pattern matching.
expect.stringMatching()
Usage
expect('123ms').toEqual(expect.stringMatching(/\d+m?s/));// Inside another matcher.expect({ status: 'passed', time: '123ms',}).toEqual({ status: expect.stringMatching(/passed|failed/), time: expect.stringMatching(/\d+m?s/),}); Copy
expect('123ms').toEqual(expect.stringMatching(/\d+m?s/));// Inside another matcher.expect({ status: 'passed', time: '123ms',}).toEqual({ status: expect.stringMatching(/passed|failed/), time: expect.stringMatching(/\d+m?s/),});
Pattern that expected string should match.
expect.stringMatching()matches a received string that in turn matches the expected pattern. Use this method inside expect(value).toEqual(expected) to perform pattern matching.Usage