Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest Expect multiple lines

I am writing tests for my js compiler and when I input a String, multiple lines are retrieved. What is retrieved is what I want to retrieve, but my test fails because I don't know how to write what is expected for jest.

This is how I call the test:

testRequireImport(
    'import { b, a } from \'@sugar/merge/*\';',
    '!EXPECTED',
    babelOptions
);

This is the reaction in the console:

    expect(received).toBe(expected)

Expected value to be (using ===):
  "import '../../top/merge/FileInTop.js';,import '../../mid/merge/FileInMid.js';,import '../../mid/merge/Second.js';,import './FileInBot.js';"
Received:
  "import '../../top/merge/FileInTop.js';
import '../../mid/merge/FileInMid.js';
import '../../mid/merge/Second.js';
import './FileInBot.js';"

Difference:

- Expected
+ Received


-import '../../top/merge/FileInTop.js';,import '../../mid/merge/FileInMid.js';,import '../../mid/merge/Second.js';,import './FileInBot.js';
+import '../../top/merge/FileInTop.js';
+import '../../mid/merge/FileInMid.js';
+import '../../mid/merge/Second.js';
+import './FileInBot.js';

Can anyone help me with writing what is expected?

like image 916
Inbar Azulay Avatar asked Sep 19 '25 17:09

Inbar Azulay


1 Answers

Your expected has commas where new lines should be, and your received has new lines instead of commas.

So make your expected match with line breaks

expect(received).toBe(expected.replace(',', '\n'));

like image 189
John Ennis Avatar answered Sep 22 '25 08:09

John Ennis