Skip to content
This repository was archived by the owner on Apr 12, 2021. It is now read-only.

Commit c400dfa

Browse files
committed
Add unit tests for trailer
1 parent 2651a74 commit c400dfa

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

tests/unit/trailer.spec.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const PDFDocument = require('../../');
2+
3+
describe('Document trailer', () => {
4+
let document;
5+
6+
beforeEach(() => {
7+
document = new PDFDocument({info: { CreationDate: new Date(Date.UTC(2018,1,1)) } });
8+
});
9+
10+
test('', (done) => {
11+
const dataLog = [];
12+
const expected = [
13+
[
14+
'7 0 obj',
15+
'<<\n/Producer 8 0 R\n/Creator 9 0 R\n/CreationDate 10 0 R\n>>'
16+
],
17+
[
18+
'8 0 obj',
19+
'(PDFKit)'
20+
],
21+
[
22+
'9 0 obj',
23+
'(PDFKit)'
24+
],
25+
[
26+
'10 0 obj',
27+
'(D:20180201000000Z)'
28+
],
29+
[
30+
'trailer',
31+
`<<\n/Size 11\n/Root 2 0 R\n/Info 7 0 R\n/ID [<8c72cf48ff87daac57e26bf1550e6979> <8c72cf48ff87daac57e26bf1550e6979>]\n>>`
32+
]
33+
];
34+
document._write = function(data) {
35+
dataLog.push(data)
36+
}
37+
document.end();
38+
setTimeout(() => {
39+
for (let i = 0; i < expected.length; ++i) {
40+
let idx = dataLog.indexOf(expected[i][0]);
41+
for (let j = 1; j < expected[i].length; ++j) {
42+
expect(dataLog[idx + j]).toEqual(expected[i][j]);
43+
}
44+
}
45+
done();
46+
}, 1);
47+
});
48+
});

0 commit comments

Comments
 (0)