Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test expect.any() implementation #2876

Closed
simylein opened this issue May 13, 2023 · 4 comments
Closed

test expect.any() implementation #2876

simylein opened this issue May 13, 2023 · 4 comments
Assignees
Labels
bug Something isn't working bun:test Something related to the `bun test` runner

Comments

@simylein
Copy link
Contributor

simylein commented May 13, 2023

What version of Bun is running?

0.6.9

What platform is your computer?

Darwin 22.5.0 arm64 arm

What steps can reproduce the bug?

please run the following code using bun test:

import { describe, expect, it } from 'bun:test';

describe('expect-any', () => {
	it('should accept any string', () => {
		expect({ name: 'alice' }).toEqual({ name: expect.any(String) });
		expect({ name: 'bob' }).toEqual({ name: expect.any(String) });
		expect({ name: 'charlie' }).toEqual({ name: expect.any(String) });
	});

	it('should accept any number', () => {
		expect({ age: 42 }).toEqual({ age: expect.any(Number) });
		expect({ age: 69 }).toEqual({ age: expect.any(Number) });
		expect({ age: 73 }).toEqual({ age: expect.any(Number) });
	});

	it('should accept any boolean', () => {
		expect({ active: false }).toEqual({ active: expect.any(Boolean) });
		expect({ active: true }).toEqual({ active: expect.any(Boolean) });
	});
});

What is the expected behavior?

The tests should pass

bun test v0.6.9 (bdb1b712)

expect-any.spec.ts:
✓ expect-any > should accept any string
✓ expect-any > should accept any number
✓ expect-any > should accept any boolean

 3 pass
 0 fail
 9 expect() calls
Ran 3 tests across 1 files [12.00ms]

What do you see instead?

The tests fail

bun test v0.6.9 (bdb1b712)

expect-any.spec.ts:
1 | import { describe, expect, it } from 'bun:test';
2 | 
3 | describe('expect-any', () => {
4 |     it('should accept any string', () => {
5 |             expect({ name: 'alice' }).toEqual({ name: expect.any(String) });
     ^
error: expect(received).toEqual(expected)

  {
+   "name": "alice"
-   "name": Any<String>
  }

- Expected  - 1
+ Received  + 1

      at /Users/simylein/expect-any.spec.ts:5:2
✗ expect-any > should accept any string
 6 |            expect({ name: 'bob' }).toEqual({ name: expect.any(String) });
 7 |            expect({ name: 'charlie' }).toEqual({ name: expect.any(String) });
 8 |    });
 9 | 
10 |    it('should accept any number', () => {
11 |            expect({ age: 42 }).toEqual({ name: expect.any(Number) });
     ^
error: expect(received).toEqual(expected)

  {
+   "age": 42
-   "name": Any<Number>
  }

- Expected  - 1
+ Received  + 1

      at /Users/simylein/expect-any.spec.ts:11:2
✗ expect-any > should accept any number
12 |            expect({ age: 69 }).toEqual({ name: expect.any(Number) });
13 |            expect({ age: 73 }).toEqual({ name: expect.any(Number) });
14 |    });
15 | 
16 |    it('should accept any boolean', () => {
17 |            expect({ active: false }).toEqual({ name: expect.any(Boolean) });
     ^
error: expect(received).toEqual(expected)

  {
+   "active": false
-   "name": Any<Boolean>
  }

- Expected  - 1
+ Received  + 1

      at /Users/simylein/expect-any.spec.ts:17:2
✗ expect-any > should accept any boolean

 0 pass
 3 fail
 3 expect() calls
Ran 3 tests across 1 files [8.00ms]

Additional information

I noticed that according to the docs this feature is not implemented yet. However, it seems to exist on the runtime right now even though there are no typings for it. I considered making this a feature request but the bug report template seemed to match better.

@simylein simylein added the bug Something isn't working label May 13, 2023
@blackmann
Copy link
Contributor

You can track the list of implemented test utilities here: #1825

@simylein
Copy link
Contributor Author

Yes I know, I just thought it is being developed because it does not throw not implemented like other utilities, hence my bug report.

@Electroid Electroid added the bun:test Something related to the `bun test` runner label May 18, 2023
@simylein simylein changed the title test expect.any implementation test expect.any() implementation Jun 8, 2023
@simylein
Copy link
Contributor Author

According to https://bun.sh/docs/test/writing#matchers expect.any() is now implemented. I saw a change in test output from {} to Any<Boolean> as example but the tests still fail.

@simylein
Copy link
Contributor Author

This is now working on the latest canary release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working bun:test Something related to the `bun test` runner
Projects
None yet
Development

No branches or pull requests

4 participants