Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrtenz committed Oct 26, 2022
1 parent 1711837 commit 132fbdb
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/utils/jest.config.js
Expand Up @@ -15,10 +15,10 @@ module.exports = {
coverageReporters: ['clover', 'json', 'lcov', 'text', 'json-summary'],
coverageThreshold: {
global: {
branches: 86.05,
functions: 97,
lines: 96.68,
statements: 96.76,
branches: 85.64,
functions: 97.19,
lines: 96.63,
statements: 96.7,
},
},
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],
Expand Down
107 changes: 107 additions & 0 deletions packages/utils/src/types.test.ts
@@ -0,0 +1,107 @@
import {
assertIsNpmSnapPackageJson,
assertIsSnapManifest,
isNpmSnapPackageJson,
isSnapManifest,
} from './types';
import { getPackageJson, getSnapManifest } from './test-utils';

describe('isNpmSnapPackageJson', () => {
it('returns true for a valid package.json', () => {
expect(isNpmSnapPackageJson(getPackageJson())).toBe(true);
});

it.each([
true,
false,
null,
undefined,
0,
1,
'',
'foo',
[],
{},
{ name: 'foo' },
{ version: '1.0.0' },
getPackageJson({ name: 'foo bar' }),
])('returns false for an invalid package.json', (value) => {
expect(isNpmSnapPackageJson(value)).toBe(false);
});
});

describe('assertIsNpmSnapPackageJson', () => {
it('does not throw for a valid package.json', () => {
expect(() => assertIsNpmSnapPackageJson(getPackageJson())).not.toThrow();
});

it.each([
true,
false,
null,
undefined,
0,
1,
'',
'foo',
[],
{},
{ name: 'foo' },
{ version: '1.0.0' },
getPackageJson({ name: 'foo bar' }),
])('throws for an invalid package.json', (value) => {
expect(() => assertIsNpmSnapPackageJson(value)).toThrow(
'"package.json" is invalid:',
);
});
});

describe('isSnapManifest', () => {
it('returns true for a valid snap manifest', () => {
expect(isSnapManifest(getSnapManifest())).toBe(true);
});

it.each([
true,
false,
null,
undefined,
0,
1,
'',
'foo',
[],
{},
{ name: 'foo' },
{ version: '1.0.0' },
getSnapManifest({ version: 'foo bar' }),
])('returns false for an invalid snap manifest', (value) => {
expect(isSnapManifest(value)).toBe(false);
});
});

describe('assertIsSnapManifest', () => {
it('does not throw for a valid snap manifest', () => {
expect(() => assertIsSnapManifest(getSnapManifest())).not.toThrow();
});

it.each([
true,
false,
null,
undefined,
0,
1,
'',
'foo',
[],
{},
{ name: 'foo' },
{ version: '1.0.0' },
getSnapManifest({ version: 'foo bar' }),
])('throws for an invalid snap manifest', (value) => {
expect(() => assertIsSnapManifest(value)).toThrow(
'"snap.manifest.json" is invalid:',
);
});
});

0 comments on commit 132fbdb

Please sign in to comment.