开玩笑地等于失败,我不知道为什么

时间:2020-10-31 05:08:42

标签: jestjs

我正在测试一个我想帮助做的软件包。但是,在我认为应该可以运行的测试中,使用这种输出会导致无数测试失败。

 ● PagingType › should create the correct filter graphql schema

    expect(received).toEqual(expected) // deep equality

    - Expected  - 20
    + Received  + 20

    - type Query {
    + type Query {
    -   test(input: Paging!): Int!
    +   test(input: Paging!): Int!
    - }
    -
    + }
    +
    - input Paging {
    + input Paging {
    -   """Paginate before opaque cursor"""
    +   """Paginate before opaque cursor"""
    -   before: ConnectionCursor
    -
    +   before: ConnectionCursor
    +
    -   """Paginate after opaque cursor"""
    +   """Paginate after opaque cursor"""
    -   after: ConnectionCursor
    -
    +   after: ConnectionCursor
    +
    -   """Paginate first"""
    +   """Paginate first"""
    -   first: Int
    -
    +   first: Int
    +
    -   """Paginate last"""
    +   """Paginate last"""
    -   last: Int
    +   last: Int
    - }
    -
    + }
    +
    - """Cursor for paging through collections"""
    + """Cursor for paging through collections"""
    - scalar ConnectionCursor
    + scalar ConnectionCursor
      ↵

      22 |   const sf = await getOrCreateSchemaFactory();
      23 |   const schema = await sf.create(resolvers);
    > 24 |   return expect(printSchema(schema)).toEqual(sdl);
         |                                      ^
      25 | };
      26 |
      27 | export const aggregateArgsTypeSDL = readGraphql(resolve(__dirname, './aggregate-args-type.graphql'));

      at Object.<anonymous>.exports.expectSDL (packages/query-graphql/__tests__/__fixtures__/index.ts:24:38)

“ toEqual”似乎无法正常工作,因为两个文本输出之间似乎没有什么错。

这是被比较字符串的console.log的另一组示例输出。失败也发生在对象上。

type Query {
        updateTest(input: UpdateOne!): Int!
      }

      input UpdateOne {
        """The id of the record to update"""
        id: ID!

        """The update to apply."""
        update: FakeUpdateOneType!
      }

      input FakeUpdateOneType {
        name: String!
      }

type Query {
        updateTest(input: UpdateOne!): Int!
      }

      input UpdateOne {
        """The id of the record to update"""
        id: ID!

        """The update to apply."""
        update: FakeUpdateOneType!
      }

      input FakeUpdateOneType {
        name: String!
      }

有人知道什么可能是错误的/正在发生什么吗?

1 个答案:

答案 0 :(得分:0)

好的。看来,这是Windows / Git问题。

这是带有JSON.stringify

的文本
console.log
      "type Query {\n  updateTest(input: UpdateOne!): Int!\n}\n\ninput UpdateOne {\n  \"\"\"The id of the record to update\"\"\"\n  id: ID!\n\n  \"\"\"The update to apply.\"\"\"\n  update: FakeUpdateOneType!\n}\n\ninput FakeUpdateOneType {\n  name: String!\n}\n"

      at Object.<anonymous>.exports.expectSDL (packages/query-graphql/__tests__/__fixtures__/index.ts:22:11)

    console.log
      "type Query {\r\n  updateTest(input: UpdateOne!): Int!\r\n}\r\n\r\ninput UpdateOne {\r\n  \"\"\"The id of the record to update\"\"\"\r\n  id: ID!\r\n\r\n  \"\"\"The update to apply.\"\"\"\r\n  update: FakeUpdateOneType!\r\n}\r\n\r\ninput FakeUpdateOneType {\r\n  name: String!\r\n}\r\n"

如果Windows的Git设置不正确,则在克隆存储库时会在换行符中添加/r/n。如果项目是使用Windows以外的任何其他软件开发的,则与toEqual的文本比较中包含换行符的操作将失败。太可笑的Jest不会说“不匹配的换行符”之类的内容,也不会显示转义字符。

要解决此问题,我使用此选项安装了Windows版Git(无论如何我都需要升级),该选项将core.autocrlf设置为“ input”。

enter image description here