diff --git a/docs/api/tsOut_model.js.html b/docs/api/tsOut_model.js.html
index 55cc04f..32975cf 100644
--- a/docs/api/tsOut_model.js.html
+++ b/docs/api/tsOut_model.js.html
@@ -419,7 +419,8 @@
tsOut/model.js
propertyDiff(key) {
// TODO: determine if returning an array is really the best option
if (key) {
- return [this.onePropertyDiff(key)];
+ const diff = this.onePropertyDiff(key);
+ return diff ? [diff] : [];
}
else {
const diffResult = [];
diff --git a/test/typescript.test.ts b/test/typescript.test.ts
index 912f356..82eab51 100644
--- a/test/typescript.test.ts
+++ b/test/typescript.test.ts
@@ -391,3 +391,22 @@ test.serial('validation errors', async (t) => {
}
}
});
+
+test.serial(
+ 'return type',
+ async (t) => {
+ const testInstance = await nohm.factory('UserMockup');
+ const diffBeforeUpdate = testInstance.propertyDiff('name');
+
+ // update the property
+ testInstance.property('name','testName');
+ const diffAfterUpdate = testInstance.propertyDiff('name');
+
+ t.deepEqual(diffBeforeUpdate, [], 'return without undefined');
+ t.deepEqual(diffAfterUpdate, [{
+ after: 'testName',
+ before: 'defaultName',
+ key: 'name',
+ }], 'return with difference in property');
+ },
+);
\ No newline at end of file
diff --git a/ts/model.ts b/ts/model.ts
index a0194c8..3ab9c73 100644
--- a/ts/model.ts
+++ b/ts/model.ts
@@ -538,10 +538,11 @@ abstract class NohmModel {
*/
public propertyDiff(
key?: keyof TProps,
- ): Array> {
+ ): Array> {
// TODO: determine if returning an array is really the best option
if (key) {
- return [this.onePropertyDiff(key)];
+ const diff = this.onePropertyDiff(key);
+ return diff ? [diff] : [];
} else {
const diffResult: Array> = [];
for (const [iterationKey] of this.properties) {