开玩笑不创建快照或失败的测试
Jest not creating snapshot or failing tests
我正在学习 React 课程,在我的第一次测试 运行ning 开玩笑之后,它似乎应该创建我的快照,但它并没有说它有,而且我看不到快照文件。
当我更改组件中的内容并再次 运行 Jest 时,它并没有像我预期的那样失败。我只是从命令行 运行ning jest
,它找到了测试,但总是通过,无论我如何更改组件。 (我假设是因为它没有创建快照来进行比较?)
我可能做错了什么?
这是测试:
import React from 'react'
import Search from './Search'
import renderer from 'react-test-renderer'
test('Search snapshot test', () => {
const component = renderer.create(<Search />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot
})
你错过了最后的()
:
expect(tree).toMatchSnapshot()
我正在学习 React 课程,在我的第一次测试 运行ning 开玩笑之后,它似乎应该创建我的快照,但它并没有说它有,而且我看不到快照文件。
当我更改组件中的内容并再次 运行 Jest 时,它并没有像我预期的那样失败。我只是从命令行 运行ning jest
,它找到了测试,但总是通过,无论我如何更改组件。 (我假设是因为它没有创建快照来进行比较?)
我可能做错了什么?
这是测试:
import React from 'react'
import Search from './Search'
import renderer from 'react-test-renderer'
test('Search snapshot test', () => {
const component = renderer.create(<Search />)
const tree = component.toJSON()
expect(tree).toMatchSnapshot
})
你错过了最后的()
:
expect(tree).toMatchSnapshot()