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

Inspect Buffers with Buffer.from([0x00, ...]) instead of Buffer([0x00, ...]) #632

Merged
merged 1 commit into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion documentation/assertions/Buffer/when-decoded-as.md
Expand Up @@ -28,7 +28,8 @@ expect(
```

```output
expected Buffer([0xE2, 0x98, 0xBA]) when decoded as 'utf-8' to equal 'happy face'
expected Buffer.from([0xE2, 0x98, 0xBA])
when decoded as 'utf-8' to equal 'happy face'

-☺
+happy face
Expand Down
4 changes: 2 additions & 2 deletions documentation/assertions/any/to-equal.md
Expand Up @@ -84,8 +84,8 @@ expect(
```

```output
expected Buffer([0x00, 0x01, 0x02, 0x48, 0x65, 0x72, 0x65, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74 /* 24 more */ ])
to equal Buffer([0x00, 0x01, 0x02, 0x48, 0x65, 0x72, 0x65, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74 /* 24 more */ ])
expected Buffer.from([0x00, 0x01, 0x02, 0x48, 0x65, 0x72, 0x65, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74 /* 24 more */ ])
to equal Buffer.from([0x00, 0x01, 0x02, 0x48, 0x65, 0x72, 0x65, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74 /* 24 more */ ])

00 01 02 48 65 72 65 20 69 73 20 74 68 65 20 74 │...Here is the t│
-68 69 6E 67 20 49 20 77 61 73 20 74 61 6C 6B 69 │hing I was talki│
Expand Down
5 changes: 4 additions & 1 deletion lib/types.js
Expand Up @@ -1273,7 +1273,10 @@ module.exports = function(expect) {
expect.addType({
name: 'Buffer',
base: 'binaryArray',
identify: Buffer.isBuffer
identify: Buffer.isBuffer,
prefix(output) {
return output.code(`Buffer.from([`, 'javascript');
}
});
}

Expand Down
4 changes: 2 additions & 2 deletions test/assertions/to-equal.spec.js
Expand Up @@ -359,8 +359,8 @@ describe('to equal assertion', () => {
);
},
'to throw',
'expected Buffer([0x00, 0x01, 0x02, 0x48, 0x65, 0x72, 0x65, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74 /* 24 more */ ])\n' +
'to equal Buffer([0x00, 0x01, 0x02, 0x48, 0x65, 0x72, 0x65, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74 /* 24 more */ ])\n' +
'expected Buffer.from([0x00, 0x01, 0x02, 0x48, 0x65, 0x72, 0x65, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74 /* 24 more */ ])\n' +
'to equal Buffer.from([0x00, 0x01, 0x02, 0x48, 0x65, 0x72, 0x65, 0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74 /* 24 more */ ])\n' +
'\n' +
' 00 01 02 48 65 72 65 20 69 73 20 74 68 65 20 74 │...Here is the t│\n' +
'-68 69 6E 67 20 49 20 77 61 73 20 74 61 6C 6B 69 │hing I was talki│\n' +
Expand Down
16 changes: 8 additions & 8 deletions test/assertions/to-satisfy.spec.js
Expand Up @@ -1299,7 +1299,7 @@ describe('to satisfy assertion', () => {
);
},
'to throw',
'expected Buffer([0x01, 0x02, 0x03]) to equal Buffer([0x01, 0x02, 0x04])\n' +
'expected Buffer.from([0x01, 0x02, 0x03]) to equal Buffer.from([0x01, 0x02, 0x04])\n' +
'\n' +
'-01 02 03 │...│\n' +
'+01 02 04 │...│'
Expand All @@ -1325,10 +1325,10 @@ describe('to satisfy assertion', () => {
);
},
'to throw',
'expected Buffer([0x62, 0x61, 0x72])\n' +
"to satisfy expect.it('to equal', Buffer([0x66, 0x6F, 0x6F]))\n" +
'expected Buffer.from([0x62, 0x61, 0x72])\n' +
"to satisfy expect.it('to equal', Buffer.from([0x66, 0x6F, 0x6F]))\n" +
'\n' +
'expected Buffer([0x62, 0x61, 0x72]) to equal Buffer([0x66, 0x6F, 0x6F])\n' +
'expected Buffer.from([0x62, 0x61, 0x72]) to equal Buffer.from([0x66, 0x6F, 0x6F])\n' +
'\n' +
'-62 61 72 │bar│\n' +
'+66 6F 6F │foo│'
Expand Down Expand Up @@ -1371,11 +1371,11 @@ describe('to satisfy assertion', () => {
)
),
'to be rejected with',
'expected Buffer([0x00, 0x01, 0x02])\n' +
"to satisfy expect.it('when delayed a little bit', 'to equal', Buffer([0x02, 0x01, 0x00]))\n" +
'expected Buffer.from([0x00, 0x01, 0x02])\n' +
"to satisfy expect.it('when delayed a little bit', 'to equal', Buffer.from([0x02, 0x01, 0x00]))\n" +
'\n' +
'expected Buffer([0x00, 0x01, 0x02])\n' +
'when delayed a little bit to equal Buffer([0x02, 0x01, 0x00])\n' +
'expected Buffer.from([0x00, 0x01, 0x02])\n' +
'when delayed a little bit to equal Buffer.from([0x02, 0x01, 0x00])\n' +
'\n' +
'-00 01 02 │...│\n' +
'+02 01 00 │...│'
Expand Down