Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing test case for validating computed property #482

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"ember-auto-import": "^1.5.2",
"@glimmer/tracking": "^1.0.0",
"ember-cli-babel": "^7.19.0",
"validated-changeset": "~0.5.10"
"validated-changeset": "~0.5.11"
},
"devDependencies": {
"@ember/optional-features": "^1.0.0",
Expand Down
36 changes: 36 additions & 0 deletions tests/unit/changeset-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1662,6 +1662,42 @@ module('Unit | Utility | changeset', function(hooks) {
]);
});

test('#validate changeset getter', async function(assert) {
class MyModel {
isOptionOne = false;
isOptionTwo = false;
isOptionThree = false;
}

const Validations = {
isOptionSelected: (newValue) => {
return newValue === true ? true : 'No options selected';
}
}

function myValidator({ key, newValue, oldValue, changes, content }) {
let validatorFn = get(Validations, key);

if (typeof validatorFn === 'function') {
return validatorFn(newValue, oldValue, changes, content);
}
}

const myObject = new MyModel();
const myChangeset = Changeset(myObject, myValidator, Validations);

Object.defineProperty(myChangeset, 'isOptionSelected', {
get() {
return this.get('isOptionOne') || this.get('isOptionTwo') || this.get('isOptionThree');
}
});
await myChangeset.validate();
assert.equal(myChangeset.isInvalid, true, 'Changeset is invalid as none of the options are selected');

set(myChangeset, 'isOptionTwo', true);
await myChangeset.validate();
assert.equal(myChangeset.isInvalid, false, 'Changeset is valid as one of the options is selected');
});

test('#changeset properties do not proxy', async function(assert) {
dummyModel.setProperties({ name: undefined, password: false, async: true, isValid: 'not proxied'});
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12777,10 +12777,10 @@ validate-npm-package-name@~2.2.2:
dependencies:
builtins "0.0.7"

validated-changeset@~0.5.10:
version "0.5.10"
resolved "https://registry.yarnpkg.com/validated-changeset/-/validated-changeset-0.5.10.tgz#4fbf68f64c6d84cac6f03b531aaff6b5aa24a35b"
integrity sha512-xPu81ng9WH1ITMcoiS9qWtGW07d97nhQguDIEBIuFG9tDE/JJyZvzCOewuY1UsQ6CRoLngLE/asmnp3BnrGe6w==
validated-changeset@~0.5.11:
version "0.5.11"
resolved "https://registry.yarnpkg.com/validated-changeset/-/validated-changeset-0.5.11.tgz#f6fe33af8320125d82f1b2f9599fad9188097c3f"
integrity sha512-ZGaaIHjGfb5yn4DbIxF0gTzGDyq0+hDJgAaQBSx8gLTUXnKlcN/wDlEhBcmRQMiNOS/oHQlN5At+0TNXIpcuWQ==

vary@~1.1.2:
version "1.1.2"
Expand Down