我通过更改规范 Lights.test.js 得到了一个工作测试:
import {testStateMachine} from 'react-automata';
import {Lights, lightMachine } from '../Components/Lights';
test('lights with imported components',()=>{
testStateMachine({ lightMachine}, Lights);
});
对此:
import { testStateMachine, withStateMachine } from 'react-automata';
import { Lights } from '../Components/Lights';
import { lightMachine } from "../Xstate/Lightmachine";
test('lights with imported components', () => {
const fixtures = {
initialData: {
states: {
'greenText': 'green light',
'yellowText':'yellow light',
'redText':'red light'
}
}
}
const StateMachine = withStateMachine(lightMachine)(Lights)
testStateMachine(StateMachine, { fixtures });
});
从示例规范react-automata/test/testStateMachine.spec.js您需要构建第StateMachine
一个。
然后,由于App
向 提供道具Lights
,使用 fixtures.initialData 在测试中做同样的事情。
该测试在 CodeSandbox 中不起作用,可能是因为我没有分叉它 - 但它在我的本地机器上运行正常。
进一步说明
该库似乎对 Jest 的版本很挑剔。我不得不从沙盒中的 24.9.0 降级到 24.7.1。不知道为什么。