spec icon indicating copy to clipboard operation
spec copied to clipboard

Matchers to implement

Open rrousselGit opened this issue 3 years ago • 5 comments

  • [x] expect(value)
  • [ ] expect.extend(matchers)
  • [ ] expect.anything()
  • [ ] expect.any(constructor)
  • [ ] expect.arrayContaining(array)
  • [ ] expect.assertions(number)
  • [ ] expect.hasAssertions()
  • [ ] expect.not.arrayContaining(array)
  • [ ] expect.not.objectContaining(object)
  • [ ] expect.not.stringContaining(string)
  • [ ] expect.not.stringMatching(string | regexp)
  • [ ] expect.objectContaining(object)
  • [ ] expect.stringContaining(string)
  • [ ] expect.stringMatching(string | regexp)
  • [ ] expect.addSnapshotSerializer(serializer)
  • [x] .not
  • [x] .resolves
  • [x] .rejects
  • [x] .toBe(value)
  • [ ] .toHaveBeenCalled()
  • [ ] .toHaveBeenCalledTimes(number)
  • [ ] .toHaveBeenCalledWith(arg1, arg2, ...)
  • [ ] .toHaveBeenLastCalledWith(arg1, arg2, ...)
  • [ ] .toHaveBeenNthCalledWith(nthCall, arg1, arg2, ....)
  • [ ] .toHaveReturned()
  • [ ] .toHaveReturnedTimes(number)
  • [ ] .toHaveReturnedWith(value)
  • [ ] .toHaveLastReturnedWith(value)
  • [ ] .toHaveNthReturnedWith(nthCall, value)
  • [ ] .toHaveLength(number)
  • [ ] .toHaveProperty(keyPath, value?)
  • [ ] .toBeCloseTo(number, numDigits?)
  • [ ] .toBeDefined()
  • [ ] .toBeFalsy()
  • [ ] .toBeGreaterThan(number | bigint)
  • [ ] .toBeGreaterThanOrEqual(number | bigint)
  • [ ] .toBeLessThan(number | bigint)
  • [ ] .toBeLessThanOrEqual(number | bigint)
  • [ ] .toBeInstanceOf(Class)
  • [ ] .toBeNull()
  • [ ] .toBeTruthy()
  • [ ] .toBeUndefined()
  • [ ] .toBeNaN()
  • [ ] .toContain(item)
  • [ ] .toContainEqual(item)
  • [x] .toEqual(value)
  • [ ] .toMatch(regexp | string)
  • [ ] .toMatchObject(object)
  • [ ] .toMatchSnapshot(propertyMatchers?, hint?)
  • [ ] .toMatchInlineSnapshot(propertyMatchers?, inlineSnapshot)
  • [ ] .toStrictEqual(value)
  • [ ] .toThrow(error?)
  • [ ] .toThrowErrorMatchingSnapshot(hint?)
  • [ ] .toThrowErrorMatchingInlineSnapshot(inlineSnapshot)

rrousselGit avatar Jul 14 '21 09:07 rrousselGit

This seems a nice ticket to work on during the hacktoberfest. I am happy to take this if it is available.

dtengeri avatar Sep 29 '22 13:09 dtengeri

@rrousselGit What would be the preferred way of implementation of . toHaveBeenCalled() and its variants? Is it okay to rely on mocktail or mockito? Or a custom implementation is expected to avoid any dependency?

dtengeri avatar Sep 30 '22 07:09 dtengeri

Be a bit careful with this list. It's copy-pasted from Jest, but we didn't really look into whether they make sense for Spec. You probably should ping me individually about matches before doing them.

What would be the preferred way of implementation of . toHaveBeenCalled() and its variants? Is it okay to rely on mocktail or mockito?

It's probably one of those that don't make sense. Ignore it :)

rrousselGit avatar Sep 30 '22 07:09 rrousselGit

@rrousselGit I plan to start with the followings. Let me know your thoughts:

.toHaveLength(number) This will be a List specific matcher.

expect([1,2]).toHaveLength(2); // PASS
expect([1,2]).toHaveLength(1); // FAIL

.toHaveProperty(dynamic key, [dynamic value?]) Map specific matcher

expect({  'hello': 'world' }).toHaveProperty('hello'); // PASS
expect({  'hello': 'world' }).toHaveProperty('hello', 'world'); // PASS
expect({  'hello': 'world' }).toHaveProperty('hello', 'dart'); // FAIL
expect({  'hello': 'world' }).toHaveProperty('bye'); // FAIL

.toBeCloseTo(number, numDigits?)

expect(0.2 + 0.1).toBeCloseTo(0.3, 5); //PASS

This could work with the closeTo matcher

.toContain(item)

expect('Hello world').toContain('Hello'); // PASS
expect([1,2]).toContain(2); // PASS
expect({  'hello': 'world' }).toContain('hello'); // PASS

Follows the contains matcher.

dtengeri avatar Oct 06 '22 14:10 dtengeri

Any matcher that has a package:test equivalent is fine.

toHaveProperty, I'm not sure. In dart, the name doesn't really fit. It's not really an object property. It's more like toHaveKey

rrousselGit avatar Oct 06 '22 14:10 rrousselGit