Javascript 浅海与浅海的区别是什么;开玩笑?
开玩笑地说,使用“浅”和“从酶渲染”有什么区别 以下是两者的一个示例: 使用浅层渲染测试渲染:Javascript 浅海与浅海的区别是什么;开玩笑?,javascript,reactjs,testing,jestjs,Javascript,Reactjs,Testing,Jestjs,开玩笑地说,使用“浅”和“从酶渲染”有什么区别 以下是两者的一个示例: 使用浅层渲染测试渲染: import "jest"; import * as React from "react"; import { shallow } from "enzyme"; import Item from "../item.component"; describe("Item", () => { it("renders correct", () => { const item = {
import "jest";
import * as React from "react";
import { shallow } from "enzyme";
import Item from "../item.component";
describe("Item", () => {
it("renders correct", () => {
const item = {
name: "A"
};
const component = shallow(
<Item item={item}/>
);
expect(component).toMatchSnapshot();
});
});
导入“jest”;
从“React”导入*作为React;
从“酶”中导入{shall};
从“./Item.component”导入项目;
描述(“项目”,()=>{
它(“呈现正确”,()=>{
常数项={
姓名:“A”
};
常数分量=浅(
);
expect(component.toMatchSnapshot();
});
});
使用渲染器测试渲染
import "jest";
import * as React from "react";
import { render } from "enzyme";
import Item from "../item.component";
describe("Item", () => {
it("renders correct", () => {
const item = {
name: "A"
};
const component = render(
<Item item={item}/>
);
expect(component).toMatchSnapshot();
});
});
导入“jest”;
从“React”导入*作为React;
从“酶”导入{render};
从“./Item.component”导入项目;
描述(“项目”,()=>{
它(“呈现正确”,()=>{
常数项={
姓名:“A”
};
常量组件=渲染(
);
expect(component.toMatchSnapshot();
});
});
这两个的典型用法是什么。我用shallow编写了所有的测试,在某些情况下,我是否应该返回并更改它以渲染?
shallow
和render
是特定于酶的,可以独立于Jest使用
shallow
只渲染顶级组件,不需要DOM。它用于单独的单元测试
render
渲染整个组件,用Cheerio将其包装,这是Node.js的jQuery实现。它用于借助类似jQuery的选择器进行黑盒集成/e2e测试。它可能有is用途,但通常使用shallow
和mount
它们都不应该与
toMatchSnapshot
一起使用,至少不需要额外的工具(enzyme to json
forshall
和mount
)。shall
和render
是酶的专用工具,可以独立于Jest使用
shallow
只渲染顶级组件,不需要DOM。它用于单独的单元测试
render
渲染整个组件,用Cheerio将其包装,这是Node.js的jQuery实现。它用于借助类似jQuery的选择器进行黑盒集成/e2e测试。它可能有is用途,但通常使用shallow
和mount
它们都不应与toMatchSnapshot
一起使用,至少在没有其他工具的情况下(enzyme to json
forshall
和mount
)。检查此项:检查此项: