Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add some tests about oneOf #294

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion test/component/expects.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { like, eachLike } = require('pactum-matchers');
const { like, eachLike, string, oneOf } = require('pactum-matchers');
const pactum = require('../../src/index');
const expect = require('chai').expect;
const fs = require('fs');
Expand Down Expand Up @@ -347,6 +347,58 @@ describe('Expects', () => {
expect(err.message).equals(`Json doesn't have type 'object' at '$' but found 'string'`);
});

it('failed json match by using oneOf', async () => {
let err;
try {
await pactum.spec()
.useInteraction({
request: {
method: 'GET',
path: '/api/users'
},
response: {
status: 200,
body: {
property: null,
}
}
})
.get('http://localhost:9393/api/users')
.expectStatus(200)
.expectJsonMatch({
property: oneOf(['']),
})
} catch (error) {
err = error;
}
expect(err.message).equals(`Json doesn't have one of the expected values at '$.property' but found 'null'`);
});

it('should match json by using oneOf', async () => {
await pactum.spec()
.useInteraction({
request: {
method: 'GET',
path: '/api/users'
},
response: {
status: 200,
body: {
property: 'test',
name: null,
gender: 'male',
}
}
})
.get('http://localhost:9393/api/users')
.expectStatus(200)
.expectJsonMatch({
property: oneOf([string(), null]),
name: oneOf([string(), null]),
gender: oneOf(['male', 'female']),
})
});

it('network error', async () => {
let err;
try {
Expand Down