如何查看chai an array + type?

时间:2017-08-17 12:39:14

标签: graphql chai

const userOverviewType = new GraphQLObjectType({
    name: 'dayOverviewData',
    fields: () => ({
        users: {
            type: new GraphQLList(user),
        },
    }),
});

我想在chai中测试这个对象类型。我的测试是:

expect(userOverviewType.getFields().users.type).to.deep.equals([ user ]);

测试失败:

1) User userOverviewType Should have a days field of type GraphQLList:
         AssertionError: expected [user] to deeply equal [ user ]
          at Assertion.assertEqual (node_modules/chai/lib/chai/core/assertions.js:485:19)
          at Assertion.ctx.(anonymous function) [as equals] (node_modules/chai/lib/chai/utils/addMethod.js:41:25)
          at Context.<anonymous> (src/test/station.server.spec.js:133:65)

正确的代码怎么样?

1 个答案:

答案 0 :(得分:0)

柴测试的类型错了。正确的测试是:

expect(userOverviewType.getFields().users.type).to.be.an.instanceof(graphql.GraphQLList);   
expect(graphql.getNamedType(userOverviewType.getFields().users.type)).to.deep.equals(userData.user);