mirror of
https://github.com/discourse/discourse.git
synced 2024-12-15 10:24:27 +08:00
a17d54d0bf
Using arrow functions changes `this` context, which is undesired in tests, e.g. it makes it impossible to setup things like pretender (`this.server`) in `beforeEach` hooks. Ember guides always use classic functions in examples (e.g. https://guides.emberjs.com/release/testing/test-types/), and that's what it uses in its own test suite, as do various addons and ember apps. It was also already used in Discourse where `this` was required. Moving forward, it will be needed in more places as we migrate toward ember-cli. (I might later add a custom rule to eslint-discourse-ember to enforce this)
37 lines
945 B
JavaScript
37 lines
945 B
JavaScript
import { moduleFor } from "ember-qunit";
|
|
import { test } from "qunit";
|
|
import WizardField from "wizard/models/wizard-field";
|
|
|
|
moduleFor("model:wizard-field");
|
|
|
|
test("basic state", function (assert) {
|
|
const w = WizardField.create({ type: "text" });
|
|
assert.ok(w.get("unchecked"));
|
|
assert.ok(!w.get("valid"));
|
|
assert.ok(!w.get("invalid"));
|
|
});
|
|
|
|
test("text - required - validation", function (assert) {
|
|
const w = WizardField.create({ type: "text", required: true });
|
|
assert.ok(w.get("unchecked"));
|
|
|
|
w.check();
|
|
assert.ok(!w.get("unchecked"));
|
|
assert.ok(!w.get("valid"));
|
|
assert.ok(w.get("invalid"));
|
|
|
|
w.set("value", "a value");
|
|
w.check();
|
|
assert.ok(!w.get("unchecked"));
|
|
assert.ok(w.get("valid"));
|
|
assert.ok(!w.get("invalid"));
|
|
});
|
|
|
|
test("text - optional - validation", function (assert) {
|
|
const f = WizardField.create({ type: "text" });
|
|
assert.ok(f.get("unchecked"));
|
|
|
|
f.check();
|
|
assert.ok(f.get("valid"));
|
|
});
|