diff options
Diffstat (limited to 'spec/frontend/matchers.js')
-rw-r--r-- | spec/frontend/matchers.js | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/frontend/matchers.js b/spec/frontend/matchers.js index 35c362d0bf5..53c6a72eea0 100644 --- a/spec/frontend/matchers.js +++ b/spec/frontend/matchers.js @@ -35,4 +35,37 @@ export default { message: () => message, }; }, + toMatchInterpolatedText(received, match) { + let clearReceived; + let clearMatch; + + try { + clearReceived = received + .replace(/\s\s+/gm, ' ') + .replace(/\s\./gm, '.') + .trim(); + } catch (e) { + return { actual: received, message: 'The received value is not a string', pass: false }; + } + try { + clearMatch = match.replace(/%{\w+}/gm, '').trim(); + } catch (e) { + return { message: 'The comparator value is not a string', pass: false }; + } + const pass = clearReceived === clearMatch; + const message = pass + ? () => ` + \n\n + Expected: ${this.utils.printExpected(clearReceived)} + To not equal: ${this.utils.printReceived(clearMatch)} + ` + : () => + ` + \n\n + Expected: ${this.utils.printExpected(clearReceived)} + To equal: ${this.utils.printReceived(clearMatch)} + `; + + return { actual: received, message, pass }; + }, }; |