Welcome to mirror list, hosted at ThFree Co, Russian Federation.

to_match_interpolated_text.js « matchers « __helpers__ « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4ce814a01b45d7337f557d3a10d10c29acfef323 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
export const 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 };
};