Skip to content

Commit

Permalink
chai-should: don't use Jest's alias names (#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristerkari committed Mar 22, 2023
1 parent b5fe411 commit 95bd8c4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 40 deletions.
58 changes: 29 additions & 29 deletions src/transformers/chai-should.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ test('removes imports and does basic conversions of should and expect (2)', () =
});
it('should map open prop to visible prop', () => {
expect(dropdown.props.visible).toThrowError(STANDARD_PROPS.open);
expect(dropdown.props.id).not.toThrowError(STANDARD_PROPS.id);
expect(dropdown.props.visible).toThrow(STANDARD_PROPS.open);
expect(dropdown.props.id).not.toThrow(STANDARD_PROPS.id);
});
thing1.equal(thing2);
Expand Down Expand Up @@ -307,10 +307,10 @@ test('converts "called"', () => {
expect(sinonSpy).to.be.not.called;
`,
`
expect(sinonSpy).toBeCalled();
expect(sinonSpy).not.toBeCalled();
expect(sinonSpy).not.toBeCalled();
expect(sinonSpy).not.toBeCalled();
expect(sinonSpy).toHaveBeenCalled();
expect(sinonSpy).not.toHaveBeenCalled();
expect(sinonSpy).not.toHaveBeenCalled();
expect(sinonSpy).not.toHaveBeenCalled();
`
)
})
Expand All @@ -324,10 +324,10 @@ test('converts "called.exactly(n)"', () => {
expect(sinonSpy).to.not.have.been.called.exactly(3)
`,
`
expect(sinonSpy).toBeCalledTimes(3)
expect(sinonSpy).not.toBeCalledTimes(3)
expect(sinonSpy).toBeCalledTimes(3)
expect(sinonSpy).not.toBeCalledTimes(3)
expect(sinonSpy).toHaveBeenCalledTimes(3)
expect(sinonSpy).not.toHaveBeenCalledTimes(3)
expect(sinonSpy).toHaveBeenCalledTimes(3)
expect(sinonSpy).not.toHaveBeenCalledTimes(3)
`
)
})
Expand All @@ -339,8 +339,8 @@ test('converts "callCount"', () => {
expect(sinonSpy).not.to.have.callCount(2);
`,
`
expect(sinonSpy).toBeCalledTimes(1);
expect(sinonSpy).not.toBeCalledTimes(2);
expect(sinonSpy).toHaveBeenCalledTimes(1);
expect(sinonSpy).not.toHaveBeenCalledTimes(2);
`
)
})
Expand All @@ -352,8 +352,8 @@ test('converts "calledOnce"', () => {
expect(sinonSpy).not.to.be.calledOnce;
`,
`
expect(sinonSpy).toBeCalledTimes(1);
expect(sinonSpy).not.toBeCalledTimes(1);
expect(sinonSpy).toHaveBeenCalledTimes(1);
expect(sinonSpy).not.toHaveBeenCalledTimes(1);
`
)
})
Expand All @@ -365,8 +365,8 @@ test('converts "calledTwice"', () => {
expect(sinonSpy).not.to.be.calledTwice;
`,
`
expect(sinonSpy).toBeCalledTimes(2);
expect(sinonSpy).not.toBeCalledTimes(2);
expect(sinonSpy).toHaveBeenCalledTimes(2);
expect(sinonSpy).not.toHaveBeenCalledTimes(2);
`
)
})
Expand All @@ -378,8 +378,8 @@ test('converts "calledThrice"', () => {
expect(sinonSpy).not.to.be.calledThrice;
`,
`
expect(sinonSpy).toBeCalledTimes(3);
expect(sinonSpy).not.toBeCalledTimes(3);
expect(sinonSpy).toHaveBeenCalledTimes(3);
expect(sinonSpy).not.toHaveBeenCalledTimes(3);
`
)
})
Expand All @@ -391,8 +391,8 @@ test('converts "calledWith"', () => {
expect(sinonSpy).not.to.be.calledWith('a', 'b');
`,
`
expect(sinonSpy).toBeCalledWith(1, 2, 3);
expect(sinonSpy).not.toBeCalledWith('a', 'b');
expect(sinonSpy).toHaveBeenCalledWith(1, 2, 3);
expect(sinonSpy).not.toHaveBeenCalledWith('a', 'b');
`
)
})
Expand All @@ -406,7 +406,7 @@ it('converts "calledWithMatch"', () => {
});
`,
`
expect(stub).toBeCalledWith(expect.objectContaining({
expect(stub).toHaveBeenCalledWith(expect.objectContaining({
foo: 'foo',
bar: 1
}));
Expand All @@ -421,8 +421,8 @@ test('converts "calledWithExactly"', () => {
expect(sinonSpy).not.to.be.calledWithExactly('a', 'b');
`,
`
expect(sinonSpy).toBeCalledWith(1, 2, 3);
expect(sinonSpy).not.toBeCalledWith('a', 'b');
expect(sinonSpy).toHaveBeenCalledWith(1, 2, 3);
expect(sinonSpy).not.toHaveBeenCalledWith('a', 'b');
`
)
})
Expand Down Expand Up @@ -955,12 +955,12 @@ test('converts "throw"', () => {
`
const err = new ReferenceError('This is a bad function.');
const fn = function() { throw err; };
expect(fn).toThrowError(ReferenceError);
expect(fn).toThrowError(Error);
expect(fn).toThrowError(/bad function/);
expect(fn).not.toThrowError('good function');
expect(fn).toThrowError(ReferenceError);
expect(fn).toThrowError(err);
expect(fn).toThrow(ReferenceError);
expect(fn).toThrow(Error);
expect(fn).toThrow(/bad function/);
expect(fn).not.toThrow('good function');
expect(fn).toThrow(ReferenceError);
expect(fn).toThrow(err);
`
)
})
Expand Down
25 changes: 15 additions & 10 deletions src/transformers/chai-should.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,13 +513,13 @@ export default function transformer(fileInfo, api, options) {
case 'function':
return typeOf(p, value, [j.literal('function')], containsNot)
case 'called':
return createCall('toBeCalled', [], rest, containsNot)
return createCall('toHaveBeenCalled', [], rest, containsNot)
case 'calledonce':
return createCall('toBeCalledTimes', [j.literal(1)], rest, containsNot)
return createCall('toHaveBeenCalledTimes', [j.literal(1)], rest, containsNot)
case 'calledtwice':
return createCall('toBeCalledTimes', [j.literal(2)], rest, containsNot)
return createCall('toHaveBeenCalledTimes', [j.literal(2)], rest, containsNot)
case 'calledthrice':
return createCall('toBeCalledTimes', [j.literal(3)], rest, containsNot)
return createCall('toHaveBeenCalledTimes', [j.literal(3)], rest, containsNot)
default:
return value
}
Expand Down Expand Up @@ -617,17 +617,22 @@ export default function transformer(fileInfo, api, options) {
)
}
case 'callcount':
return createCall('toBeCalledTimes', args, rest, containsNot)
return createCall('toHaveBeenCalledTimes', args, rest, containsNot)
case 'calledwith':
return createCall('toBeCalledWith', args, rest, containsNot)
return createCall('toHaveBeenCalledWith', args, rest, containsNot)
case 'calledwithmatch':
return createCall('toBeCalledWith', args.map(containing), rest, containsNot)
return createCall(
'toHaveBeenCalledWith',
args.map(containing),
rest,
containsNot
)
case 'calledwithexactly':
return createCall('toBeCalledWith', args, rest, containsNot)
return createCall('toHaveBeenCalledWith', args, rest, containsNot)
case 'exactly':
// handle `expect(sinonSpy).to.have.called.exactly(3)`
if (chainContains('called', value.callee, isPrefix)) {
return createCall('toBeCalledTimes', [firstArg], rest, containsNot)
return createCall('toHaveBeenCalledTimes', [firstArg], rest, containsNot)
}
return value
case 'equalto':
Expand Down Expand Up @@ -663,7 +668,7 @@ export default function transformer(fileInfo, api, options) {
)
}
case 'throw':
return createCall('toThrowError', args, rest, containsNot)
return createCall('toThrow', args, rest, containsNot)
case 'string':
return createCall('toContain', args, rest, containsNot)
case 'state':
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/should.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test('removes imports and does basic conversions of should.js', () => {
expect(user).toHaveProperty('name', 'tj');
expect(user).toHaveProperty('name', 'tj');
expect(true).toBeTruthy();
expect(foo).toThrowError(/^Description/);
expect(foo).toThrow(/^Description/);
expect(foo).toBeUndefined();
`
)
Expand Down

0 comments on commit 95bd8c4

Please sign in to comment.