• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript enzyme.ReactWrapper类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript enzyme.ShallowWrapper类代码示例发布时间:2022-05-25
下一篇:
TypeScript enzyme.mount函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap