You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importchaifrom'chai';import{JSDOM}from'jsdom';import{renderToString}from'../../../src/wcc.js';constexpect=chai.expect;describe('Run WCC For ',function(){constLABEL='Single Custom Element w/ Declarative Shadow DOM';letdom;before(asyncfunction(){const{ html }=awaitrenderToString(newURL('./src/footer.js',import.meta.url));dom=newJSDOM(html);});describe(LABEL,function(){it('should have one top level <template> with an open shadowroot',function(){expect(dom.window.document.querySelectorAll('template[shadowroot="open"]').length).to.equal(1);expect(dom.window.document.querySelectorAll('template').length).to.equal(1);});describe('<footer> component and content',function(){letfooter;before(asyncfunction(){footer=newJSDOM(dom.window.document.querySelectorAll('template[shadowroot="open"]')[0].innerHTML);});it('should have one <footer> tag within the <template> shadowroot',function(){expect(footer.window.document.querySelectorAll('footer').length).to.equal(1);});it('should have the expected content for the <footer> tag',function(){expect(footer.window.document.querySelectorAll('h4 a').textContent).to.contain(/My Blog/);});});});});
But I'm curious to see if would be more pragmatic to just use fixtures instead? In other words, like in snapshot testing, capture the expected outcome as an HTML file, and just match the response to the file on disk.
Details
So for the above component test, instead of testing via DOM, we just test against a fixture file in the test directory
Type of Change
Summary
In our specs currently, we convert the HTML from
wcc
into DOM and query it via JSDOMSo for this component
We would test it like so
But I'm curious to see if would be more pragmatic to just use fixtures instead? In other words, like in snapshot testing, capture the expected outcome as an HTML file, and just match the response to the file on disk.
Details
So for the above component test, instead of testing via DOM, we just test against a fixture file in the test directory
I think it's easier to reason about and easier to edit, and should make writing tests a LOT easier. (IMO)
The text was updated successfully, but these errors were encountered: