当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript enzyme.ReactWrapper类代码示例

本文整理汇总了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);
  };
}
开发者ID:dzearing,项目名称:office-ui-fabric-react,代码行数:12,代码来源:injectWrapperMethod.ts

示例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);
  });
});
开发者ID:,项目名称:,代码行数:59,代码来源:

示例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);
  });
开发者ID:AdrianDiaz81,项目名称:sp-dev-fx-extensions,代码行数:9,代码来源:ReactMegaMenuApplicationCustomizer.test.ts

示例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);
开发者ID:AdrianDiaz81,项目名称:sp-dev-fx-extensions,代码行数:8,代码来源:ReactMegaMenuApplicationCustomizer.test.ts

示例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);
  });
开发者ID:,项目名称:,代码行数:16,代码来源:


注:本文中的enzyme.ReactWrapper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。