Upgrade to Pro — share decks privately, control downloads, hide ads and more …

It's a (testing) trap! - Common testing pitfall...

It's a (testing) trap! - Common testing pitfalls and how to solve them

Avatar for Ramona Schwering

Ramona Schwering

June 08, 2021
Tweet

More Decks by Ramona Schwering

Other Decks in Programming

Transcript

  1. describe('deprecated.plugin', () => { it('Property: Should throw an error if

    the deprecated prop is used', () => { … }); });
  2. describe('Context menu', () => { it('should open the context menu

    on click', async () => { const wrapper = createWrapper(); expect(wrapper.vm).toBeTruthy(); await wrapper.trigger('click'); const selector = '.sw-context-menu'; expect(wrapper.find(selector).isVisible()).toBeTruthy(); }); });
  3. describe('Context menu', () => { it('should open the context menu

    on click', () => { }); }); // Arrange const wrapper = createWrapper(); const selector = '.sw-context-menu';
  4. describe('Context menu', () => { it('should open the context menu

    on click', () => { }); }); // Arrange const wrapper = createWrapper(); const selector = '.sw-context-menu'; // Act await wrapper.trigger('click');
  5. describe('Context menu', () => { it('should open the context menu

    on click', () => { }); }); // Arrange const wrapper = createWrapper(); const selector = '.sw-context-menu'; // Act await wrapper.trigger('click'); // Assert expect(wrapper.vm).toBeTruthy(); expect(wrapper.find(selector).isVisible()).toBeTruthy();
  6. “…arrange my test == what I’m given.” “…act in my

    test == when something happens.” “…assert the results == something happens then this is what I expect as the outcome.”
  7. “…arrange my test == what I’m given.” “…act in my

    test == when something happens.” “…assert the results == something happens then this is what I expect as the outcome.”
  8. describe('Context menu', () => { it('should open the context menu

    on click', () => { // Given const contextButtonSelector = 'sw-context-button'; const contextMenuSelector = '.sw-context-menu'; // When let contextMenu = wrapper.find(contextMenuSelector); expect(contextMenu.isVisible()).toBe(false); const contextButton = wrapper.find(contextButtonSelector); await contextButton.trigger('click'); // Then contextMenu = wrapper.find(contextMenuSelector); expect(contextMenu.isVisible()).toBe(true); }); });
  9. it('should create and read product', () => { … cy.get('.sw-field—product-name').type('T-Shirt

    Ackbar'); cy.get('.sw-select-product__select_manufacturer') .type('Space Company’); … });
  10. it('should create and read product', () => { … cy.get('.sw-field—product-name').type('T-Shirt

    Ackbar'); cy.get('.sw-select-product__select_manufacturer') .type('Space Company’); … });