mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
DEV: Clean up assertions in transformer-test (#29928)
This commit is contained in:
@@ -55,11 +55,10 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
api.addValueTransformerName("home-logo-href"); // existing core transformer
|
api.addValueTransformerName("home-logo-href"); // existing core transformer
|
||||||
|
|
||||||
// testing warning about core transformers
|
// testing warning about core transformers
|
||||||
assert.strictEqual(
|
assert.true(
|
||||||
this.consoleWarnStub.calledWith(
|
this.consoleWarnStub.calledWith(
|
||||||
sinon.match(/matches existing core transformer/)
|
sinon.match(/matches existing core transformer/)
|
||||||
),
|
),
|
||||||
true,
|
|
||||||
"logs warning to the console about existing core transformer with the same name"
|
"logs warning to the console about existing core transformer with the same name"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -67,17 +66,15 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
this.consoleWarnStub.reset();
|
this.consoleWarnStub.reset();
|
||||||
|
|
||||||
api.addValueTransformerName("new-plugin-transformer"); // first time should go through
|
api.addValueTransformerName("new-plugin-transformer"); // first time should go through
|
||||||
assert.strictEqual(
|
assert.true(
|
||||||
this.consoleWarnStub.notCalled,
|
this.consoleWarnStub.notCalled,
|
||||||
true,
|
|
||||||
"did not log warning to the console"
|
"did not log warning to the console"
|
||||||
);
|
);
|
||||||
|
|
||||||
api.addValueTransformerName("new-plugin-transformer"); // second time log a warning
|
api.addValueTransformerName("new-plugin-transformer"); // second time log a warning
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.true(
|
||||||
this.consoleWarnStub.calledWith(sinon.match(/is already registered/)),
|
this.consoleWarnStub.calledWith(sinon.match(/is already registered/)),
|
||||||
true,
|
|
||||||
"logs warning to the console about transformer already added with the same name"
|
"logs warning to the console about transformer already added with the same name"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -87,22 +84,20 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
acceptNewTransformerNames();
|
acceptNewTransformerNames();
|
||||||
|
|
||||||
withPluginApi("1.34.0", (api) => {
|
withPluginApi("1.34.0", (api) => {
|
||||||
assert.strictEqual(
|
assert.false(
|
||||||
transformerWasAdded(
|
transformerWasAdded(
|
||||||
"a-new-plugin-transformer",
|
"a-new-plugin-transformer",
|
||||||
transformerTypes.VALUE
|
transformerTypes.VALUE
|
||||||
),
|
),
|
||||||
false,
|
|
||||||
"initially the transformer does not exists"
|
"initially the transformer does not exists"
|
||||||
);
|
);
|
||||||
api.addValueTransformerName("a-new-plugin-transformer"); // second time log a warning
|
api.addValueTransformerName("a-new-plugin-transformer"); // second time log a warning
|
||||||
assert.strictEqual(
|
assert.true(
|
||||||
transformerWasAdded(
|
transformerWasAdded(
|
||||||
"a-new-plugin-transformer",
|
"a-new-plugin-transformer",
|
||||||
transformerTypes.VALUE
|
transformerTypes.VALUE
|
||||||
),
|
),
|
||||||
true,
|
"the new transformer is added"
|
||||||
"the new transformer was added"
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -132,17 +127,16 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
test("warns if transformer is unknown", function (assert) {
|
test("warns if transformer is unknown", function (assert) {
|
||||||
withPluginApi("1.34.0", (api) => {
|
withPluginApi("1.34.0", (api) => {
|
||||||
const result = api.registerValueTransformer("whatever", () => "foo");
|
const result = api.registerValueTransformer("whatever", () => "foo");
|
||||||
assert.notOk(
|
assert.false(
|
||||||
result,
|
result,
|
||||||
"registerValueTransformer returns false if the transformer name does not exist"
|
"registerValueTransformer returns false if the transformer name does not exist"
|
||||||
);
|
);
|
||||||
|
|
||||||
// testing warning about core transformers
|
// testing warning about core transformers
|
||||||
assert.strictEqual(
|
assert.true(
|
||||||
this.consoleWarnStub.calledWith(
|
this.consoleWarnStub.calledWith(
|
||||||
sinon.match(/is unknown and will be ignored/)
|
sinon.match(/is unknown and will be ignored/)
|
||||||
),
|
)
|
||||||
true
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -167,9 +161,8 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
const transformerWasRegistered = (name) =>
|
const transformerWasRegistered = (name) =>
|
||||||
applyValueTransformer(name, false);
|
applyValueTransformer(name, false);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.false(
|
||||||
transformerWasRegistered("test-transformer"),
|
transformerWasRegistered("test-transformer"),
|
||||||
false,
|
|
||||||
"value did not change. transformer is not registered yet"
|
"value did not change. transformer is not registered yet"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -177,15 +170,14 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
"test-transformer",
|
"test-transformer",
|
||||||
() => true
|
() => true
|
||||||
);
|
);
|
||||||
assert.ok(
|
assert.true(
|
||||||
result,
|
result,
|
||||||
"registerValueTransformer returns true if the transformer was registered"
|
"registerValueTransformer returns true if the transformer is registered"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.true(
|
||||||
transformerWasRegistered("test-transformer"),
|
transformerWasRegistered("test-transformer"),
|
||||||
true,
|
"the transformer is registered successfully, the value did change"
|
||||||
"the transformer was registered successfully. the value did change."
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -217,53 +209,53 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("accepts only simple objects as context", function (assert) {
|
test("accepts only simple objects as context", function (assert) {
|
||||||
assert.ok(
|
assert.true(
|
||||||
notThrows(() =>
|
notThrows(() =>
|
||||||
applyValueTransformer("test-value1-transformer", "foo")
|
applyValueTransformer("test-value1-transformer", "foo")
|
||||||
),
|
),
|
||||||
"it won't throw an error if context is not passed"
|
"doesn't throw an error if context is not passed"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.ok(
|
assert.true(
|
||||||
notThrows(() =>
|
notThrows(() =>
|
||||||
applyValueTransformer("test-value1-transformer", "foo", undefined)
|
applyValueTransformer("test-value1-transformer", "foo", undefined)
|
||||||
),
|
),
|
||||||
"it won't throw an error if context is undefined"
|
"doesn't throw an error if context is undefined"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.ok(
|
assert.true(
|
||||||
notThrows(() =>
|
notThrows(() =>
|
||||||
applyValueTransformer("test-value1-transformer", "foo", null)
|
applyValueTransformer("test-value1-transformer", "foo", null)
|
||||||
),
|
),
|
||||||
"it won't throw an error if context is null"
|
"doesn't throw an error if context is null"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.ok(
|
assert.true(
|
||||||
notThrows(() =>
|
notThrows(() =>
|
||||||
applyValueTransformer("test-value1-transformer", "foo", {
|
applyValueTransformer("test-value1-transformer", "foo", {
|
||||||
pojo: true,
|
pojo: true,
|
||||||
property: "foo",
|
property: "foo",
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
"it won't throw an error if context is a POJO"
|
"doesn't throw an error if context is a POJO"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => applyValueTransformer("test-value1-transformer", "foo", ""),
|
() => applyValueTransformer("test-value1-transformer", "foo", ""),
|
||||||
/context must be a simple JS object/,
|
/context must be a simple JS object/,
|
||||||
"it will throw an error if context is a string"
|
"throws an error if context is a string"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => applyValueTransformer("test-value1-transformer", "foo", 0),
|
() => applyValueTransformer("test-value1-transformer", "foo", 0),
|
||||||
/context must be a simple JS object/,
|
/context must be a simple JS object/,
|
||||||
"it will throw an error if context is a number"
|
"throws an error if context is a number"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() => applyValueTransformer("test-value1-transformer", "foo", false),
|
() => applyValueTransformer("test-value1-transformer", "foo", false),
|
||||||
/context must be a simple JS object/,
|
/context must be a simple JS object/,
|
||||||
"it will throw an error if context is a boolean value"
|
"throws an error if context is a boolean value"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
@@ -274,7 +266,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
() => "function"
|
() => "function"
|
||||||
),
|
),
|
||||||
/context must be a simple JS object/,
|
/context must be a simple JS object/,
|
||||||
"it will throw an error if context is a function"
|
"throws an error if context is a function"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
@@ -287,7 +279,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
})
|
})
|
||||||
),
|
),
|
||||||
/context must be a simple JS object/,
|
/context must be a simple JS object/,
|
||||||
"it will throw an error if context is an Ember object"
|
"throws an error if context is an Ember object"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
@@ -300,7 +292,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
})
|
})
|
||||||
),
|
),
|
||||||
/context must be a simple JS object/,
|
/context must be a simple JS object/,
|
||||||
"it will throw an error if context is an Ember component"
|
"throws an error if context is an Ember component"
|
||||||
);
|
);
|
||||||
|
|
||||||
class Testable {}
|
class Testable {}
|
||||||
@@ -313,7 +305,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
new Testable()
|
new Testable()
|
||||||
),
|
),
|
||||||
/context must be a simple JS object/,
|
/context must be a simple JS object/,
|
||||||
"it will throw an error if context is an instance of a class"
|
"throws an error if context is an instance of a class"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -359,7 +351,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
testObject2.value2,
|
testObject2.value2,
|
||||||
],
|
],
|
||||||
[1, 1, 2, 2],
|
[1, 1, 2, 2],
|
||||||
"it returns the default values when there are no transformers registered"
|
"returns the default values when there are no transformers registered"
|
||||||
);
|
);
|
||||||
|
|
||||||
withPluginApi("1.34.0", (api) => {
|
withPluginApi("1.34.0", (api) => {
|
||||||
@@ -371,7 +363,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
[testObject1.value1, testObject2.value1],
|
[testObject1.value1, testObject2.value1],
|
||||||
[10, 20],
|
[10, 20],
|
||||||
"when a transformer was registered, it returns the transformed value"
|
"when a transformer is registered, it returns the transformed value"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
@@ -414,17 +406,17 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
function (error) {
|
function (error) {
|
||||||
return error.message === "sabotaged";
|
return error.message === "sabotaged";
|
||||||
},
|
},
|
||||||
"by default it throws an exception on tests when the transformer registered has an error"
|
"by default throws an exception on tests when the transformer registered has an error"
|
||||||
);
|
);
|
||||||
|
|
||||||
disableThrowingApplyExceptionOnTests();
|
disableThrowingApplyExceptionOnTests();
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
[testObject1.value1, testObject2.value1],
|
[testObject1.value1, testObject2.value1],
|
||||||
[1, 2],
|
[1, 2],
|
||||||
"it catches the exception and returns the default value when the only transformer registered has an error"
|
"catches the exception and returns the default value when the only transformer registered has an error"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.true(
|
||||||
this.documentDispatchEventStub.calledWith(
|
this.documentDispatchEventStub.calledWith(
|
||||||
sinon.match
|
sinon.match
|
||||||
.instanceOf(CustomEvent)
|
.instanceOf(CustomEvent)
|
||||||
@@ -441,8 +433,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
true,
|
"dispatches an event to display a message do admins when an exception is caught in a transformer"
|
||||||
"it dispatches an event to display a message do admins when an exception is caught in a transformer"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
withPluginApi("1.34.0", (api) => {
|
withPluginApi("1.34.0", (api) => {
|
||||||
@@ -454,7 +445,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
[testObject1.value1, testObject2.value1],
|
[testObject1.value1, testObject2.value1],
|
||||||
[0, 0],
|
[0, 0],
|
||||||
"it catches the exception and and keeps processing the queue when there are others transformers registered"
|
"catches the exception and and keeps processing the queue when there are others transformers registered"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -478,7 +469,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
prop2: false,
|
prop2: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.strictEqual(value, true, "the value was transformed");
|
assert.true(value, "the value is transformed");
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
expectedContext,
|
expectedContext,
|
||||||
{
|
{
|
||||||
@@ -522,7 +513,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
testObject.sequence.join(""),
|
testObject.sequence.join(""),
|
||||||
"correct",
|
"correct",
|
||||||
`the transformers applied in the expected sequence will produce the word "correct"`
|
`the transformers applied in the expected sequence produce the word "correct"`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -554,7 +545,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
applyMutableValueTransformer("test-mutable-transformer", value);
|
applyMutableValueTransformer("test-mutable-transformer", value);
|
||||||
assert.strictEqual(mutated, true, "the value was mutated");
|
assert.true(mutated, "the value is mutated");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("raises an exception if the transformer returns a value different from undefined", function (assert) {
|
test("raises an exception if the transformer returns a value different from undefined", function (assert) {
|
||||||
@@ -607,11 +598,10 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
api.addBehaviorTransformerName("home-logo-href"); // existing core transformer
|
api.addBehaviorTransformerName("home-logo-href"); // existing core transformer
|
||||||
|
|
||||||
// testing warning about core transformers
|
// testing warning about core transformers
|
||||||
assert.strictEqual(
|
assert.true(
|
||||||
this.consoleWarnStub.calledWith(
|
this.consoleWarnStub.calledWith(
|
||||||
sinon.match(/matches existing core transformer/)
|
sinon.match(/matches existing core transformer/)
|
||||||
),
|
),
|
||||||
true,
|
|
||||||
"logs warning to the console about existing core transformer with the same name"
|
"logs warning to the console about existing core transformer with the same name"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -619,17 +609,15 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
this.consoleWarnStub.reset();
|
this.consoleWarnStub.reset();
|
||||||
|
|
||||||
api.addBehaviorTransformerName("new-plugin-transformer"); // first time should go through
|
api.addBehaviorTransformerName("new-plugin-transformer"); // first time should go through
|
||||||
assert.strictEqual(
|
assert.true(
|
||||||
this.consoleWarnStub.notCalled,
|
this.consoleWarnStub.notCalled,
|
||||||
true,
|
"does not log warning to the console"
|
||||||
"did not log warning to the console"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
api.addBehaviorTransformerName("new-plugin-transformer"); // second time log a warning
|
api.addBehaviorTransformerName("new-plugin-transformer"); // second time log a warning
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.true(
|
||||||
this.consoleWarnStub.calledWith(sinon.match(/is already registered/)),
|
this.consoleWarnStub.calledWith(sinon.match(/is already registered/)),
|
||||||
true,
|
|
||||||
"logs warning to the console about transformer already added with the same name"
|
"logs warning to the console about transformer already added with the same name"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -639,22 +627,20 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
acceptNewTransformerNames();
|
acceptNewTransformerNames();
|
||||||
|
|
||||||
withPluginApi("1.35.0", (api) => {
|
withPluginApi("1.35.0", (api) => {
|
||||||
assert.strictEqual(
|
assert.false(
|
||||||
transformerWasAdded(
|
transformerWasAdded(
|
||||||
"a-new-plugin-transformer",
|
"a-new-plugin-transformer",
|
||||||
transformerTypes.BEHAVIOR
|
transformerTypes.BEHAVIOR
|
||||||
),
|
),
|
||||||
false,
|
|
||||||
"initially the transformer does not exists"
|
"initially the transformer does not exists"
|
||||||
);
|
);
|
||||||
api.addBehaviorTransformerName("a-new-plugin-transformer"); // second time log a warning
|
api.addBehaviorTransformerName("a-new-plugin-transformer"); // second time log a warning
|
||||||
assert.strictEqual(
|
assert.true(
|
||||||
transformerWasAdded(
|
transformerWasAdded(
|
||||||
"a-new-plugin-transformer",
|
"a-new-plugin-transformer",
|
||||||
transformerTypes.BEHAVIOR
|
transformerTypes.BEHAVIOR
|
||||||
),
|
),
|
||||||
true,
|
"the new transformer is added"
|
||||||
"the new transformer was added"
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -684,17 +670,16 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
test("warns if transformer is unknown ans returns false", function (assert) {
|
test("warns if transformer is unknown ans returns false", function (assert) {
|
||||||
withPluginApi("1.35.0", (api) => {
|
withPluginApi("1.35.0", (api) => {
|
||||||
const result = api.registerBehaviorTransformer("whatever", () => "foo");
|
const result = api.registerBehaviorTransformer("whatever", () => "foo");
|
||||||
assert.notOk(
|
assert.false(
|
||||||
result,
|
result,
|
||||||
"registerBehaviorTransformer returns false if the transformer name does not exist"
|
"registerBehaviorTransformer returns false if the transformer name does not exist"
|
||||||
);
|
);
|
||||||
|
|
||||||
// testing warning about core transformers
|
// testing warning about core transformers
|
||||||
assert.strictEqual(
|
assert.true(
|
||||||
this.consoleWarnStub.calledWith(
|
this.consoleWarnStub.calledWith(
|
||||||
sinon.match(/is unknown and will be ignored/)
|
sinon.match(/is unknown and will be ignored/)
|
||||||
),
|
)
|
||||||
true
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -729,30 +714,30 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
value,
|
value,
|
||||||
null,
|
null,
|
||||||
"value is null. behavior callback was not executed yet"
|
"value is null, behavior callback was not executed yet"
|
||||||
);
|
);
|
||||||
|
|
||||||
transformerWasRegistered("test-transformer");
|
transformerWasRegistered("test-transformer");
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
value,
|
value,
|
||||||
"DEFAULT_CALLBACK",
|
"DEFAULT_CALLBACK",
|
||||||
"value was set by the default callback. transformer is not registered yet"
|
"value is set by the default callback, transformer is not registered yet"
|
||||||
);
|
);
|
||||||
|
|
||||||
const result = api.registerBehaviorTransformer(
|
const result = api.registerBehaviorTransformer(
|
||||||
"test-transformer",
|
"test-transformer",
|
||||||
({ context }) => context.setValue("TRANSFORMED_CALLBACK")
|
({ context }) => context.setValue("TRANSFORMED_CALLBACK")
|
||||||
);
|
);
|
||||||
assert.ok(
|
assert.true(
|
||||||
result,
|
result,
|
||||||
"registerBehaviorTransformer returns true if the transformer was registered"
|
"registerBehaviorTransformer returns true if the transformer is registered"
|
||||||
);
|
);
|
||||||
|
|
||||||
transformerWasRegistered("test-transformer");
|
transformerWasRegistered("test-transformer");
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
value,
|
value,
|
||||||
"TRANSFORMED_CALLBACK",
|
"TRANSFORMED_CALLBACK",
|
||||||
"the transformer was registered successfully. the value did change."
|
"the transformer is registered successfully, the value did change"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -791,14 +776,14 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("accepts only simple objects as context", function (assert) {
|
test("accepts only simple objects as context", function (assert) {
|
||||||
assert.ok(
|
assert.true(
|
||||||
notThrows(() =>
|
notThrows(() =>
|
||||||
applyBehaviorTransformer("test-behavior1-transformer", () => true)
|
applyBehaviorTransformer("test-behavior1-transformer", () => true)
|
||||||
),
|
),
|
||||||
"it won't throw an error if context is not passed"
|
"doesn't throw an error if context is not passed"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.ok(
|
assert.true(
|
||||||
notThrows(() =>
|
notThrows(() =>
|
||||||
applyBehaviorTransformer(
|
applyBehaviorTransformer(
|
||||||
"test-behavior1-transformer",
|
"test-behavior1-transformer",
|
||||||
@@ -806,10 +791,10 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
undefined
|
undefined
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
"it won't throw an error if context is undefined"
|
"doesn't throw an error if context is undefined"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.ok(
|
assert.true(
|
||||||
notThrows(() =>
|
notThrows(() =>
|
||||||
applyBehaviorTransformer(
|
applyBehaviorTransformer(
|
||||||
"test-behavior1-transformer",
|
"test-behavior1-transformer",
|
||||||
@@ -817,17 +802,17 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
null
|
null
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
"it won't throw an error if context is null"
|
"doesn't throw an error if context is null"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.ok(
|
assert.true(
|
||||||
notThrows(() =>
|
notThrows(() =>
|
||||||
applyBehaviorTransformer("test-behavior1-transformer", () => true, {
|
applyBehaviorTransformer("test-behavior1-transformer", () => true, {
|
||||||
pojo: true,
|
pojo: true,
|
||||||
property: "foo",
|
property: "foo",
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
"it won't throw an error if context is a POJO"
|
"doesn't throw an error if context is a POJO"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
@@ -838,14 +823,14 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
""
|
""
|
||||||
),
|
),
|
||||||
/context must be a simple JS object/,
|
/context must be a simple JS object/,
|
||||||
"it will throw an error if context is a string"
|
"throws an error if context is a string"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
() =>
|
() =>
|
||||||
applyBehaviorTransformer("test-behavior1-transformer", () => true, 0),
|
applyBehaviorTransformer("test-behavior1-transformer", () => true, 0),
|
||||||
/context must be a simple JS object/,
|
/context must be a simple JS object/,
|
||||||
"it will throw an error if context is a number"
|
"throws an error if context is a number"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
@@ -856,7 +841,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
false
|
false
|
||||||
),
|
),
|
||||||
/context must be a simple JS object/,
|
/context must be a simple JS object/,
|
||||||
"it will throw an error if context is a boolean behavior"
|
"throws an error if context is a boolean behavior"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
@@ -867,7 +852,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
() => "function"
|
() => "function"
|
||||||
),
|
),
|
||||||
/context must be a simple JS object/,
|
/context must be a simple JS object/,
|
||||||
"it will throw an error if context is a function"
|
"throws an error if context is a function"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
@@ -880,7 +865,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
})
|
})
|
||||||
),
|
),
|
||||||
/context must be a simple JS object/,
|
/context must be a simple JS object/,
|
||||||
"it will throw an error if context is an Ember object"
|
"throws an error if context is an Ember object"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.throws(
|
assert.throws(
|
||||||
@@ -893,7 +878,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
})
|
})
|
||||||
),
|
),
|
||||||
/context must be a simple JS object/,
|
/context must be a simple JS object/,
|
||||||
"it will throw an error if context is an Ember component"
|
"throws an error if context is an Ember component"
|
||||||
);
|
);
|
||||||
|
|
||||||
class Testable {}
|
class Testable {}
|
||||||
@@ -906,7 +891,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
new Testable()
|
new Testable()
|
||||||
),
|
),
|
||||||
/context must be a simple JS object/,
|
/context must be a simple JS object/,
|
||||||
"it will throw an error if context is an instance of a class"
|
"throws an error if context is an instance of a class"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -970,7 +955,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
[testObject1.value, testObject2.value],
|
[testObject1.value, testObject2.value],
|
||||||
[20, 40],
|
[20, 40],
|
||||||
"when a transformer was registered, the method now performs1 transformed behavior"
|
"when a transformer is registered, the method now performs transformed behavior"
|
||||||
);
|
);
|
||||||
|
|
||||||
testObject1.incValue();
|
testObject1.incValue();
|
||||||
@@ -1022,7 +1007,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const testObject = new Testable();
|
const testObject = new Testable();
|
||||||
assert.deepEqual(testObject.value, null, "initially the value is null");
|
assert.strictEqual(testObject.value, null, "initially the value is null");
|
||||||
|
|
||||||
withPluginApi("1.35.0", (api) => {
|
withPluginApi("1.35.0", (api) => {
|
||||||
api.registerBehaviorTransformer(
|
api.registerBehaviorTransformer(
|
||||||
@@ -1039,10 +1024,10 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
|
|
||||||
const done = assert.async();
|
const done = assert.async();
|
||||||
testObject.initializeValue().then(() => {
|
testObject.initializeValue().then(() => {
|
||||||
assert.deepEqual(
|
assert.strictEqual(
|
||||||
testObject.value,
|
testObject.value,
|
||||||
"slow foo was too late",
|
"slow foo was too late",
|
||||||
"the value was changed after the async behavior"
|
"the value is changed after the async behavior"
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -1087,13 +1072,13 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const testObject = new Testable();
|
const testObject = new Testable();
|
||||||
assert.deepEqual(testObject.value, null, "initially the value is null");
|
assert.strictEqual(testObject.value, null, "initially the value is null");
|
||||||
|
|
||||||
await testObject.initializeValue();
|
await testObject.initializeValue();
|
||||||
assert.deepEqual(
|
assert.strictEqual(
|
||||||
testObject.value,
|
testObject.value,
|
||||||
"slow foo",
|
"slow foo",
|
||||||
"the value was changed after the async behavior"
|
"the value is changed after the async behavior"
|
||||||
);
|
);
|
||||||
|
|
||||||
withPluginApi("1.35.0", (api) => {
|
withPluginApi("1.35.0", (api) => {
|
||||||
@@ -1110,10 +1095,10 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
|
|
||||||
testObject.clearValue();
|
testObject.clearValue();
|
||||||
await testObject.initializeValue();
|
await testObject.initializeValue();
|
||||||
assert.deepEqual(
|
assert.strictEqual(
|
||||||
testObject.value,
|
testObject.value,
|
||||||
"slow foo was too late",
|
"slow foo was too late",
|
||||||
"when a transformer was registered, the method now performs transformed behavior"
|
"when a transformer is registered, the method now performs transformed behavior"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1166,7 +1151,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
function (error) {
|
function (error) {
|
||||||
return error.message === "sabotaged";
|
return error.message === "sabotaged";
|
||||||
},
|
},
|
||||||
"by default it throws an exception on tests when the transformer registered has an error"
|
"by default throws an exception on tests when the transformer registered has an error"
|
||||||
);
|
);
|
||||||
|
|
||||||
disableThrowingApplyExceptionOnTests();
|
disableThrowingApplyExceptionOnTests();
|
||||||
@@ -1177,10 +1162,10 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
[testObject1.value, testObject2.value],
|
[testObject1.value, testObject2.value],
|
||||||
[2, 4],
|
[2, 4],
|
||||||
"it catches the exception and follows the default behavior when the only transformer registered has an error"
|
"catches the exception and follows the default behavior when the only transformer registered has an error"
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(
|
assert.true(
|
||||||
this.documentDispatchEventStub.calledWith(
|
this.documentDispatchEventStub.calledWith(
|
||||||
sinon.match
|
sinon.match
|
||||||
.instanceOf(CustomEvent)
|
.instanceOf(CustomEvent)
|
||||||
@@ -1197,8 +1182,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
true,
|
"dispatches an event to display a message do admins when an exception is caught in a transformer"
|
||||||
"it dispatches an event to display a message do admins when an exception is caught in a transformer"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
withPluginApi("1.35.0", (api) => {
|
withPluginApi("1.35.0", (api) => {
|
||||||
@@ -1216,7 +1200,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
[testObject1.value, testObject2.value],
|
[testObject1.value, testObject2.value],
|
||||||
[0, 0],
|
[0, 0],
|
||||||
"it catches the exception and and keeps processing the queue when there are others transformers registered"
|
"catches the exception and and keeps processing the queue when there are others transformers registered"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1245,7 +1229,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
assert.strictEqual(behavior, "ALTERED", "the behavior was transformed");
|
assert.strictEqual(behavior, "ALTERED", "the behavior is transformed");
|
||||||
assert.deepEqual(
|
assert.deepEqual(
|
||||||
expectedContext,
|
expectedContext,
|
||||||
{
|
{
|
||||||
@@ -1280,7 +1264,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
const testObject = new Testable();
|
const testObject = new Testable();
|
||||||
testObject.buildValue();
|
testObject.buildValue();
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.strictEqual(
|
||||||
testObject.value,
|
testObject.value,
|
||||||
"!",
|
"!",
|
||||||
`initially buildValue value only generates "!"`
|
`initially buildValue value only generates "!"`
|
||||||
@@ -1316,7 +1300,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
testObject.value,
|
testObject.value,
|
||||||
"correct!",
|
"correct!",
|
||||||
`the transformers applied in the sequence will produce the word "correct!"`
|
`the transformers applied in the sequence produce the word "correct!"`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1344,7 +1328,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
const testObject = new Testable();
|
const testObject = new Testable();
|
||||||
testObject.buildValue();
|
testObject.buildValue();
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.strictEqual(
|
||||||
testObject.value,
|
testObject.value,
|
||||||
"!",
|
"!",
|
||||||
`initially buildValue value only generates "!"`
|
`initially buildValue value only generates "!"`
|
||||||
@@ -1403,7 +1387,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
const testObject = new Testable();
|
const testObject = new Testable();
|
||||||
testObject.buildValue();
|
testObject.buildValue();
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.strictEqual(
|
||||||
testObject.value,
|
testObject.value,
|
||||||
"!",
|
"!",
|
||||||
`initially buildValue value only generates "!"`
|
`initially buildValue value only generates "!"`
|
||||||
@@ -1421,7 +1405,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
"test-behavior1-transformer",
|
"test-behavior1-transformer",
|
||||||
({ context, next }) => {
|
({ context, next }) => {
|
||||||
next();
|
next();
|
||||||
context.pushValue("was");
|
context.pushValue("is");
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
api.registerBehaviorTransformer(
|
api.registerBehaviorTransformer(
|
||||||
@@ -1437,8 +1421,8 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
|
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
testObject.value,
|
testObject.value,
|
||||||
"order was reverted",
|
"order is reverted",
|
||||||
`the transformers applied in the sequence will produce the expression "order was reverted"`
|
`the transformers applied in the sequence produce the expression "order was reverted"`
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1470,7 +1454,7 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
const testObject = new Testable();
|
const testObject = new Testable();
|
||||||
testObject.buildValue();
|
testObject.buildValue();
|
||||||
|
|
||||||
assert.deepEqual(
|
assert.strictEqual(
|
||||||
testObject.value,
|
testObject.value,
|
||||||
"!",
|
"!",
|
||||||
`initially buildValue value only generates "!"`
|
`initially buildValue value only generates "!"`
|
||||||
|
|||||||
Reference in New Issue
Block a user