最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Jest Expect multiple lines - Stack Overflow

programmeradmin1浏览0评论

I am writing tests for my js piler 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?

I am writing tests for my js piler 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?

Share Improve this question edited Mar 19, 2017 at 14:38 Andreas Köberle 111k58 gold badges280 silver badges307 bronze badges asked Mar 17, 2017 at 15:18 Inbar AzulayInbar Azulay 2871 gold badge6 silver badges28 bronze badges 2
  • You haven't said what you actually want to happen – Aron Commented Mar 17, 2017 at 15:30
  • @Aron I want my test to succeed. What I receive is correct, but I want to know how to write the expected to be equal to the received. – Inbar Azulay Commented Mar 17, 2017 at 16:04
Add a ment  | 

1 Answer 1

Reset to default 3

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

So make your expected match with line breaks

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

发布评论

评论列表(0)

  1. 暂无评论