make snapshot more robust
This commit is contained in:
@@ -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 () {
|
||||
|
||||
@@ -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
|
||||
/*
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user