Skip to content

Commit

Permalink
Bump to v0.0.15
Browse files Browse the repository at this point in the history
Test fixes
  • Loading branch information
Rohansi committed Jun 17, 2024
1 parent cad89b1 commit 2c4f46d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-class-model",
"version": "0.0.13",
"version": "0.0.15",
"type": "commonjs",
"description": "State management for React with hooks, inspired by Flutter's scoped_model",
"main": "dist/index.js",
Expand Down
6 changes: 5 additions & 1 deletion src/Persistence/TestClasses.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { key, prop } from '.';
import { Model, watch } from '../Model';

export function expectModelToStrictEqual<T extends Model>(actual: T, expected: T) {
expect(actual['props']).toStrictEqual(expected['props']);
}

export class Point {
@prop()
public x: number | undefined;
Expand Down Expand Up @@ -69,7 +73,7 @@ export class PlayerModel extends Model {

export class TeamModel extends Model {
@prop({ ctor: PlayerModel }) @watch
public members: Player[];
public members: PlayerModel[];
}

export class Variable extends Model {
Expand Down
14 changes: 7 additions & 7 deletions src/Persistence/__tests__/Serialization.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { setupSerialization } from '..';
import { requirePersistence } from '../Persistence';
import { deserializeCopy, toSerializable } from '../Serialization';
import { Line, NumberList, Player, PlayerModel, Point, PointList, Team, TeamModel, Variable, VariableSet } from '../TestClasses';
import { expectModelToStrictEqual, Line, NumberList, Player, PlayerModel, Point, PointList, Team, TeamModel, Variable, VariableSet } from '../TestClasses';

describe('#toSerializable', () => {
describe('primitives', () => {
Expand Down Expand Up @@ -317,9 +317,9 @@ describe('#deserializeCopy', () => {
const changed = deserializeCopy(teamModelPersistence, team, { members: [player1, player2, player3] });
expect(changed).toBe(true);
expect(team.members).toHaveLength(3);
expect(team.members[0]).toStrictEqual(player1);
expect(team.members[1]).toStrictEqual(player2);
expect(team.members[2]).toStrictEqual(player3);
expectModelToStrictEqual(team.members[0], player1);
expectModelToStrictEqual(team.members[1], player2);
expectModelToStrictEqual(team.members[2], player3);
});

it('updates objects in keyed array fields', () => {
Expand All @@ -336,9 +336,9 @@ describe('#deserializeCopy', () => {
const changed = deserializeCopy(teamModelPersistence, team, { members: [player1, player2, player3] });
expect(changed).toBe(true);
expect(team.members).toHaveLength(3);
expect(team.members[0]).toStrictEqual(player1);
expect(team.members[1]).toStrictEqual(player2);
expect(team.members[2]).toStrictEqual(player3);
expectModelToStrictEqual(team.members[0], player1);
expectModelToStrictEqual(team.members[1], player2);
expectModelToStrictEqual(team.members[2], player3);
});

it('removes old objects from keyed array fields', () => {
Expand Down

0 comments on commit 2c4f46d

Please sign in to comment.