Add unit tests
This commit is contained in:
parent
7233c83874
commit
248ac5c37b
1 changed files with 27 additions and 0 deletions
|
@ -34,5 +34,32 @@ describe('nativeImage module', () => {
|
||||||
assert.equal(image.getSize().height, 190);
|
assert.equal(image.getSize().height, 190);
|
||||||
assert.equal(image.getSize().width, 538);
|
assert.equal(image.getSize().width, 538);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Gets an NSImage pointer on OS X', () => {
|
||||||
|
if (process.platform !== 'darwin') return;
|
||||||
|
|
||||||
|
const imagePath = `${path.join(__dirname, 'fixtures', 'api')}${path.sep}..${path.sep}${path.join('assets', 'logo.png')}`;
|
||||||
|
const image = nativeImage.createFromPath(imagePath);
|
||||||
|
const nsimage = image.asNativeRepresentation('nsimage');
|
||||||
|
|
||||||
|
assert.equal(nsimage.length, 8);
|
||||||
|
|
||||||
|
// If all bytes are null, that's Bad
|
||||||
|
assert.equal(nsimage.reduce((acc,x) => acc || (x != 0)), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Throws when asNativeRepresentation gets a bogus value', () => {
|
||||||
|
const imagePath = `${path.join(__dirname, 'fixtures', 'api')}${path.sep}..${path.sep}${path.join('assets', 'logo.png')}`;
|
||||||
|
const image = nativeImage.createFromPath(imagePath);
|
||||||
|
|
||||||
|
let shouldDie = true;
|
||||||
|
try {
|
||||||
|
image.asNativeRepresentation('__foobar__');
|
||||||
|
} catch (e) {
|
||||||
|
shouldDie = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.equal(shouldDie, false);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue