本文整理汇总了TypeScript中enzyme.ReactWrapper类的典型用法代码示例。如果您正苦于以下问题:TypeScript ReactWrapper类的具体用法?TypeScript ReactWrapper怎么用?TypeScript ReactWrapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ReactWrapper类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: injectWrapperMethod
export function injectWrapperMethod(wrapper: ReactWrapper<any, any>, methodName: string, fn: () => void): void {
const originalMethod = (wrapper.instance() as any)[methodName];
if (typeof originalMethod !== 'function') {
throw new Error(`Tried to override the method ${methodName} on a ReactWrapper that does not have that function`);
}
(wrapper.instance() as any)[methodName] = function (prevProps: any): void {
fn();
originalMethod.call(this, prevProps);
};
}
示例2: describe
describe('Enzyme props, state, lifecycle events test', () => {
let reactComponent: ReactWrapper<IIceCreamShopProps, IIceCreamShopState>;
beforeEach(() => {
reactComponent = mount(React.createElement(
IceCreamShop,
{
iceCreamProvider: new IceCreamFakeProvider(),
strings: {
TitleLabel: "PnP Ice Cream Shop"
} as IIceCreamShopWebPartStrings
}
));
});
afterEach(() => {
reactComponent.unmount();
});
it('should has test title is the props', () => {
expect(reactComponent.props().strings.TitleLabel).toBe("PnP Ice Cream Shop");
});
it('should has initial state', () => {
const state = reactComponent.state();
expect(state.hasBoughtIceCream).toBe(false);
expect(state.quantity).toBe(1);
expect(state.selectedIceCream).toBe(null);
});
it('should buy form be hidden initialy', () => {
const buyForm = reactComponent.find("#buyForm");
expect(buyForm.length).toBe(0);
});
it('should unhide the buy form after ice cream has been selected', () => {
reactComponent.update(); // http://airbnb.io/enzyme/docs/api/ShallowWrapper/update.html
// more advanced selector
const selectIceCreamButton = reactComponent.find("#iceCreamFlavoursList button").first();
selectIceCreamButton.simulate('click');
// after the selectIceCreamButton is clicked
// the buy form should be rendered
// lets try to find in in the component
const buyForm = reactComponent.find("#buyForm");
expect(buyForm.length).toBeGreaterThan(0);
});
});
示例3: it
it("should button be visible", () => {
let cssSelector: string = "[data-id='menuButton']";
let menuButton: ReactWrapper<React.AllHTMLAttributes<{}>>;
menuButton = reactComponent.find(cssSelector);
expect(menuButton.length).to.be.greaterThan(0);
});
示例4: before
before((done) => {
// stub the menu provider so we use fake data to test.
menuProviderStub = sinon.stub(MenuSPListProvider.prototype, "getAllItems").returns(fakeMenuData);
// mount the react component.
reactComponent = mount(React.createElement(
MegaMenuComponent,
{
menuProvider: new MenuSPListProvider("http://test.com")
}
));
let menuButton: ReactWrapper<React.AllHTMLAttributes<{}>>;
menuButton = reactComponent.find("[data-id='menuButton']").first();
menuButton.simulate("click"); // open the menu.
setTimeout(done, 50); // all the menu items should be loaded after 200.
});
开发者ID:AdrianDiaz81,项目名称:sp-dev-fx-extensions,代码行数:20,代码来源:ReactMegaMenuApplicationCustomizer.test.ts
示例5: setTimeout
setTimeout(() => {
expect(reactComponent.state().showPanel).to.be.equal(false);
expect(reactComponent.state().menuItems.length).to.be.equal(2);
done();
}, 50);
示例6: it
it('should unhide the buy form after ice cream has been selected', () => {
reactComponent.update(); // http://airbnb.io/enzyme/docs/api/ShallowWrapper/update.html
// more advanced selector
const selectIceCreamButton = reactComponent.find("#iceCreamFlavoursList button").first();
selectIceCreamButton.simulate('click');
// after the selectIceCreamButton is clicked
// the buy form should be rendered
// lets try to find in in the component
const buyForm = reactComponent.find("#buyForm");
expect(buyForm.length).toBeGreaterThan(0);
});