Skip to content

Commit

Permalink
test: add tests for applyProps
Browse files Browse the repository at this point in the history
  • Loading branch information
trezy committed Jul 2, 2024
1 parent e3fbd73 commit a88fe5f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/helpers/appendChild.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { log } from './log.js';
* Adds elements to our application.
*
* @param {Instance} parentInstance
* @param {Instance} childInstance
* @param {Instance | null} childInstance
*/
export function appendChild(parentInstance, childInstance)
{
Expand Down
52 changes: 52 additions & 0 deletions test/unit/helpers/applyProps.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Container } from 'pixi.js';
import {
describe,
expect,
it,
} from 'vitest';
import { applyProps } from '../../../src/helpers/applyProps.js';
import { prepareInstance } from '../../../src/helpers/prepareInstance.js';

describe('applyProps', () =>
{
describe('when given instance props', () =>
{
it('updates the target instance', () =>
{
expect(applyProps).to.be.a('function');
const instance = prepareInstance(new Container());

expect(instance.x).to.equal(0);

const result = applyProps(instance, { x: 100 });

expect(result).to.equal(instance);
expect(instance.x).to.equal(100);
});
});

describe('when given a diff set', () =>
{
it('updates the target instance', () =>
{
expect(applyProps).to.be.a('function');
const instance = prepareInstance(new Container());

expect(instance.x).to.equal(0);

const result = applyProps(instance, {
changes: [
[
'x',
100,
false,
[],
],
],
});

expect(result).to.equal(instance);
expect(instance.x).to.equal(100);
});
});
});

0 comments on commit a88fe5f

Please sign in to comment.