如何测试 Stencil.js 状态变化?
How to test Stencil.js state change?
我正在尝试找出如何使用 jest 测试 Stencil Web 组件中的状态更改。我是一般测试的新手,发现您可以使用 Enzyme 来测试 React 组件中的状态更改,但我一直无法弄清楚如何使用 Stencil 组件进行测试。我该怎么做?
一般不建议测试组件(state)的内部逻辑,而是测试public API(props, events)
但是如果你想测试它,我建议你检查 Testing documentation on stencils original website. If by testing a component you mean test it by instantiating a component explicitly 那么这意味着你将要测试普通 javascript class 的实例。因此,如果您的状态变量标记为私有(这是最佳做法),那么您将无法编译它,因为 TS 会抛出编译错误。因此,作为一个选项(也是我现在看到的唯一选项),您可以使这些状态成员 public 并在您的 expects().
中检查它们
我正在尝试找出如何使用 jest 测试 Stencil Web 组件中的状态更改。我是一般测试的新手,发现您可以使用 Enzyme 来测试 React 组件中的状态更改,但我一直无法弄清楚如何使用 Stencil 组件进行测试。我该怎么做?
一般不建议测试组件(state)的内部逻辑,而是测试public API(props, events)
但是如果你想测试它,我建议你检查 Testing documentation on stencils original website. If by testing a component you mean test it by instantiating a component explicitly 那么这意味着你将要测试普通 javascript class 的实例。因此,如果您的状态变量标记为私有(这是最佳做法),那么您将无法编译它,因为 TS 会抛出编译错误。因此,作为一个选项(也是我现在看到的唯一选项),您可以使这些状态成员 public 并在您的 expects().
中检查它们