make snapshot more robust

This commit is contained in:
jfh
2020-10-16 23:59:30 +02:00
parent b957a3c5aa
commit 8a1607a8cd
3 changed files with 24 additions and 6 deletions

View File

@@ -3,10 +3,7 @@ import {
} from '../../support/ui-test-helper.js';
const testSnapshot = () => {
// cy.get('#tool_source').click({force: true});
// cy.get('#svg_source_textarea').invoke('val').toMatchSnapshot();
// cy.get('#tool_source_save').click({force: true});
cy.get('#svgcontent').toMatchSnapshot();
cy.get('#svgcontent').cleanSnapshot();
};
describe('use various parts of svg-edit', function () {

View File

@@ -4,8 +4,6 @@ import '../../../instrumented/editor/jquery-ui/jquery-ui-1.8.17.custom.min.js';
import SvgCanvas from '../../../instrumented/svgcanvas/svgcanvas.js';
// import '../../../instrumented/'
describe('Basic Module', function () {
// helper functions
/*

View File

@@ -23,3 +23,26 @@
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
// remove the style attributes that is causing differences in snapshots
const ngAttributes = ['style'];
Cypress.Commands.add(
'cleanSnapshot',
{
prevSubject: true
},
(subject, snapshotOptions) => {
let html = subject[0].outerHTML;
for (const attribute of ngAttributes) {
const expression = new RegExp(`${attribute}[^= ]*="[^"]*"`, 'g');
html = html.replace(expression, '');
}
html = html.replace(/<!--[\s\S]*?-->/g, '');
const sanitisedBody = new DOMParser().parseFromString(html, 'text/html').querySelector('body');
return cy.wrap(sanitisedBody.firstChild).toMatchSnapshot();
}
);