How to use @open-wc/testing - 10 common examples

To help you get started, we’ve selected a few @open-wc/testing examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Dabolus / share-menu / test / share-menu.spec.ts View on Github external
it('generates an accessible markup', async () => {
        // For some reason we need to create a new share menu,
        // otherwise axe will complain about "no elements in frame context"
        const possiblyAccessibleShareMenu: ShareMenu = await fixture(html`
          
        `);

        await expect(possiblyAccessibleShareMenu).to.be.accessible();
      });
github Dabolus / share-menu / test / share-menu.spec.ts View on Github external
it('creates a button only for the specified socials and in the specified order', () => {
        shareMenu.socials = ['facebook', 'skype', 'telegram'];
        const buttons = shareMenu.shadowRoot.querySelectorAll<
          HTMLButtonElement
        >('button.social');

        expect(buttons.length).to.equal(3);
        expect(buttons[0].title).to.equal(
          shareMenu['_supportedSocials'].facebook.title,
        );
        expect(buttons[1].title).to.equal(
          shareMenu['_supportedSocials'].skype.title,
        );
        expect(buttons[2].title).to.equal(
          shareMenu['_supportedSocials'].telegram.title,
        );

        // Restore socials
        shareMenu.socials = Object.keys(shareMenu['_supportedSocials']);
      });
github mkay581 / router-component / tests / router-component-tests.ts View on Github external
it('updates the window pathname', async () => {
            window.history.pushState({ triggerRouteChange: false }, null, '/page3');
            expect(location.pathname).to.equal('/page3');
        });
github mkay581 / router-component / tests / router-component-tests.ts View on Github external
it('updates the document title that matches the current location after calling pushState', async () => {
        await fixture(html`
            
                
                
            
        `);
        window.history.pushState({}, document.title, '/page1');
        expect(document.title).to.equal('Test1');
        const state = { my: 'state' };
        const pageTitle = 'the title';
        const url = '/page2';
        window.history.pushState(state, pageTitle, url);
        expect(document.title).to.equal('Test2');
    });
github Dabolus / share-menu / test / share-menu.spec.ts View on Github external
it('renders image only socials if is-imsage is truthy', () => {
        shareMenu.isImage = 'yes';
        expect(
          shareMenu.shadowRoot.querySelector(
            `button.social#${imageOnlySocialId}`,
          ),
        ).not.to.be.null;
      });
github mkay581 / router-component / tests / router-component-tests.ts View on Github external
it('shows a warning when attempting to go to a route that is not handled after popstate is called', async () => {
        const component: RouterComponent = await fixture(html`
            
                
                
            
        `);

        window.history.pushState({}, document.title, '/page1');
        const newPath = 'nope';
        consoleWarn.resetHistory();
        component.show(newPath);
        expect(consoleWarn.args[0]).to.deep.equal([
            `Navigated to path "${newPath}" but there is no matching ` +
                `element with a path that matches. Maybe you should implement a catch-all route with the path attribute of ".*"?`
        ]);
    });
github mkay581 / router-component / tests / router-component-tests.ts View on Github external
it('scrolls back to top of page if there is no hash', async () => {
            window.history.pushState({}, document.title, '/page1');
            const popstate = new PopStateEvent('popstate', { state: {} });
            const windowScrollToStub = sinon.stub(window, 'scrollTo');
            window.dispatchEvent(popstate);
            expect(windowScrollToStub).to.be.calledOnceWithExactly({ behavior: 'auto', top: 0 });
            windowScrollToStub.restore();
        });
    });
github Dabolus / share-menu / test / share-menu.spec.ts View on Github external
it('defaults to all of them unless specified', () => {
        expect(shareMenu.socials).to.deep.equal(
          Object.keys(shareMenu['_supportedSocials']),
        );
      });
github mkay581 / router-component / tests / router-component-tests.ts View on Github external
it('should continue to show the current page and not show a warning when show has been called with the same url', async () => {
        const component: RouterComponent = await fixture(html`
            
                
                
            
        `);

        const pathname = '/page1';
        window.history.pushState({}, document.title, pathname);
        consoleWarn.resetHistory();
        component.show(pathname);
        expect(consoleWarn.callCount).to.equal(0);
        expect(document.body.querySelector('first-page')).to.not.be.null;
        expect(document.body.querySelector('second-page')).to.be.null;
    });
github Dabolus / share-menu / test / share-menu.spec.ts View on Github external
const fakeOpenWindow = fake((url: string) => {
            expect(url).not.to.contain('i=');
          });
          shareMenu['_openWindow'] = fakeOpenWindow;

@open-wc/testing

Testing following open-wc recommendations

MIT
Latest version published 5 months ago

Package Health Score

92 / 100
Full package analysis