-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Similar to expectValue, you can use expectKey to assert that the response body contains a given a key. This can be very useful when testing against live APIs where data can change, but the schema should remain the same.
- Loading branch information
1 parent
aeb7ff6
commit 34e0789
Showing
6 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
describe('#expectKey', function() { | ||
it('returns an error when the key is missing from the response', function(done) { | ||
api() | ||
.json() | ||
.get('/keys') | ||
.expectKey('non_existing') | ||
.end(function(err) { | ||
err.should.be.ok; | ||
done(); | ||
}); | ||
}); | ||
|
||
it('does not return an error when the key is present', function(done) { | ||
api() | ||
.json() | ||
.get('/keys') | ||
.expectKey('hippie') | ||
.end(done); | ||
}); | ||
|
||
it('should work with falsy values if key is present', function(done) { | ||
api() | ||
.json() | ||
.get('/keys') | ||
.expectKey('blank') | ||
.expectKey('nullable') | ||
.expectKey('boolean') | ||
.end(done); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters