I am using React, Jest and Typescript and following these docs to create a unit test using this code:
expect(HorizontalNotIndented.props().includedProp).to.equal(dummyValue);
I have all types installed but I am getting the error Property 'to' does not exist on type 'FunctionMatchers<any>'.
when I use to
in the test.
It seems there maybe some confusion over whether to
is coming form Jest or Jasmine? I'm not 100% sure but I am following the Enzyme docs exactly.
I am now having problems structuring this test - following the docs and the comment below does not seem to allow the test to work. I am trying to test for props rendering properly:
const dummyValue = {
background: {
color: 'rgba(38, 176, 17, 0.2)',
value: 100,
},
foreground: {
color: 'rgb(38, 176, 17)',
value: 80,
},
};
const HorizontalNotIndented = shallow(
<Horizontal
value={dummyValue}
/>,
);
HorizontalNotIndented.setProps({
value
});
describe('HCGauge', () => {
test('Test to see if props are in rendered component', () => {
expect(HorizontalNotIndented.props().value).toEqual(dummyValue);
Throws the error:
expect(received).toEqual(expected) // deep equality
Expected: {"background": {"color": "rgba(38, 176, 17, 0.2)", "value": 100}, "foreground": {"color": "rgb(38, 176, 17)", "value": 80}}
Received: undefined
62 | test('Test to see if props are in rendered component', () => {
63 | // expect('value' in HorizontalNotIndented.props()).toEqual(dummyValue);
> 64 | expect(HorizontalNotIndented.props().includedProp).toEqual(dummyValue);
|
If you are using Jest you should use .toBe()
instead of .to.equal()
as described here:
https://jestjs.io/docs/en/expect.html#tobevalue
If the parameter (dummyValue
) is an object you should use .toMatchObject()
as described here:
https://jestjs.io/docs/en/expect.html#tomatchobjectobject
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With