Skip to content

Commit

Permalink
Add spaces between tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnw committed Nov 13, 2023
1 parent 85e0cc5 commit 64d225a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions js-api-spec/value/color/color-4-channels.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('Color 4 SassColor Channels', () => {

describe(space.name, () => {
let color: SassColor;

beforeEach(() => {
color = space.constructor(...space.pink);
});
Expand All @@ -29,6 +30,7 @@ describe('Color 4 SassColor Channels', () => {
expect(color.channelsOrNull.size).toBe(space.channels.length);
expect(List.isList(color.channelsOrNull)).toBeTrue();
});

it('returns channel value or null, excluding alpha', () => {
const pinkCases = channelCases(...space.pink);
pinkCases.forEach(channels => {
Expand All @@ -39,12 +41,14 @@ describe('Color 4 SassColor Channels', () => {
});
});
});

describe('channels', () => {
it('returns a list', () => {
expect(color.channels).toFuzzyEqualList(space.pink);
expect(color.channels.size).toBe(space.channels.length);
expect(List.isList(color.channels)).toBeTrue();
});

it('returns channel value or 0, excluding alpha', () => {
const pinkCases = channelCases(...space.pink);
pinkCases.forEach(channels => {
Expand All @@ -54,6 +58,7 @@ describe('Color 4 SassColor Channels', () => {
});
});
});

it('isChannelMissing', () => {
const pinkCases = channelCases(...space.pink);
pinkCases.forEach(channels => {
Expand All @@ -67,6 +72,7 @@ describe('Color 4 SassColor Channels', () => {
expect(_color.isChannelMissing('alpha')).toBe(expected[3]);
});
});

describe('channel', () => {
describe('without space specified', () => {
it('throws an error if channel not in space', () => {
Expand All @@ -78,12 +84,14 @@ describe('Color 4 SassColor Channels', () => {
expect(() => color.channel(channel)).toThrow();
});
});

it('returns value if no space specified', () => {
space.channels.forEach((channel, index) => {
expect(color.channel(channel)).toFuzzyEqual(space.pink[index]);
});
expect(color.channel('alpha')).toEqual(1);
});

it('returns 0 for missing channels', () => {
const nullColor = space.constructor(null, null, null, null);
space.channels.forEach(channel => {
Expand All @@ -92,6 +100,7 @@ describe('Color 4 SassColor Channels', () => {
expect(nullColor.channel('alpha')).toEqual(0);
});
});

describe('with space specified', () => {
spaceNames.forEach(destinationSpaceId => {
it(`throws an error if channel not in ${destinationSpaceId}`, () => {
Expand All @@ -109,6 +118,7 @@ describe('Color 4 SassColor Channels', () => {
});
});
});

spaceNames.forEach(destinationSpaceId => {
it(`returns value when ${destinationSpaceId} is specified`, () => {
const destinationSpace = spaces[destinationSpaceId];
Expand All @@ -128,6 +138,7 @@ describe('Color 4 SassColor Channels', () => {
});
});
});

describe('alpha', () => {
it('returns value if set', () => {
function colorWithAlpha(alpha: number | null) {
Expand Down Expand Up @@ -166,6 +177,7 @@ describe('Color 4 SassColor Channels', () => {
);
});
}

const [ch1, ch2, ch3] = space.ranges;
if (space.hasPowerless) {
// test powerless channels
Expand Down
4 changes: 4 additions & 0 deletions js-api-spec/value/color/color-4-conversions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ describe('Color 4 SassColors Conversions', () => {
});
});
});

it('should throw on invalid alpha', () => {
expect(() => color.change({alpha: -1})).toThrow();
expect(() => color.change({alpha: 1.1})).toThrow();
Expand All @@ -170,17 +171,20 @@ describe('Color 4 SassColors Conversions', () => {
it('is true for in gamut colors in own space', () => {
expect(color.isInGamut()).toBe(true);
});

spaceNames.forEach(destinationSpaceId => {
it(`is true for in gamut colors in ${destinationSpaceId}`, () => {
const destinationSpace = spaces[destinationSpaceId];
expect(color.isInGamut(destinationSpace.name)).toBe(true);
});
});

it(`is ${!space.hasOutOfGamut} for out of range colors in own space`, () => {
const outOfGamut = space.constructor(...space.gamutExamples[0][0]);
expect(outOfGamut.isInGamut()).toBe(!space.hasOutOfGamut);
});
});

describe('toGamut', () => {
space.gamutExamples.forEach(([input, output]) => {
it(`in own space, ${input} -> ${output}`, () => {
Expand Down
1 change: 1 addition & 0 deletions js-api-spec/value/color/color-4-nonparametizable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('Color 4 SassColors Non-parametizable', () => {
});
});
});

it('channel with space specified, missing returns 0', () => {
const cases: [SassColor, KnownColorSpace, ChannelName][] = [
[constructors.oklch(null, null, null), 'lch', 'hue'],
Expand Down
2 changes: 2 additions & 0 deletions js-api-spec/value/color/color-4-spaces.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('Color 4 SassColors Spaces', () => {
beforeEach(() => {
color = space.constructor(...space.pink);
});

it('is a value', () => {
expect(color).toBeInstanceOf(Value);
});
Expand Down Expand Up @@ -60,6 +61,7 @@ describe('Color 4 SassColors Spaces', () => {
channels[index] = -1;
expect(() => space.constructor(...channels)).toThrow();
});

// TODO: Failing for oklab and oklch in dart-sass
it('throws on lightness higher than bounds', () => {
const index = space.channels.findIndex(
Expand Down

0 comments on commit 64d225a

Please sign in to comment.