test("setting values should call function return value", function() { // get each property twice. Verify return. var keys = w('computed dependent dependentFront computedCached dependentCached'); var values = w('value1 value2'); forEach(keys, function(key) { equal(object.set(key, values[0]), object, fmt('Try #1: object.set(%@, %@) should run function', [key, values[0]])); equal(object.set(key, values[1]), object, fmt('Try #2: object.set(%@, %@) should run function', [key, values[1]])); equal(object.set(key, values[1]), object, fmt('Try #3: object.set(%@, %@) should not run function since it is setting same value as before', [key, values[1]])); }); // verify each call count. cached should only be called once forEach(keys, function(key) { var calls = object[key + 'Calls'], idx; var expectedLength; // Cached properties first check their cached value before setting the // property. Other properties blindly call set. expectedLength = 3; equal(calls.length, expectedLength, fmt('set(%@) should be called the right amount of times', [key])); for(idx=0;idx<2;idx++) { equal(calls[idx], values[idx], fmt('call #%@ to set(%@) should have passed value %@', [idx+1, key, values[idx]])); } }); });
QUnit.test('setting values should call function return value', function() { // get each property twice. Verify return. var keys = w('computed dependent dependentFront computedCached dependentCached'); var values = w('value1 value2'); keys.forEach((key) => { equal(object.set(key, values[0]), values[0], `Try #1: object.set(${key}, ${values[0]}) should run function`); equal(object.set(key, values[1]), values[1], `Try #2: object.set(${key}, ${values[1]}) should run function`); equal(object.set(key, values[1]), values[1], `Try #3: object.set(${key}, ${values[1]}) should not run function since it is setting same value as before`); }); // verify each call count. cached should only be called once keys.forEach((key) => { var calls = object[key + 'Calls']; var idx, expectedLength; // Cached properties first check their cached value before setting the // property. Other properties blindly call set. expectedLength = 3; equal(calls.length, expectedLength, `set(${key}) should be called the right amount of times`); for (idx = 0;idx < 2;idx++) { equal(calls[idx], values[idx], `call #${idx + 1} to set(${key}) should have passed value ${values[idx]}`); } }); });
QUnit.test('getting values should call function return value', function() { // get each property twice. Verify return. var keys = w('computed computedCached dependent dependentFront dependentCached'); keys.forEach(function(key) { equal(object.get(key), key, `Try #1: object.get(${key}) should run function`); equal(object.get(key), key, `Try #2: object.get(${key}) should run function`); }); // verify each call count. cached should only be called once w('computedCalls dependentFrontCalls dependentCalls').forEach((key) => { equal(object[key].length, 2, `non-cached property ${key} should be called 2x`); }); w('computedCachedCalls dependentCachedCalls').forEach((key) => { equal(object[key].length, 1, `non-cached property ${key} should be called 1x`); }); });
test("getting values should call function return value", function() { // get each property twice. Verify return. var keys = w('computed computedCached dependent dependentFront dependentCached'); forEach(keys, function(key) { equal(object.get(key), key, fmt('Try #1: object.get(%@) should run function', [key])); equal(object.get(key), key, fmt('Try #2: object.get(%@) should run function', [key])); }); // verify each call count. cached should only be called once forEach(w('computedCalls dependentFrontCalls dependentCalls'), function(key) { equal(object[key].length, 2, fmt('non-cached property %@ should be called 2x', [key])); }); forEach(w('computedCachedCalls dependentCachedCalls'), function(key) { equal(object[key].length, 1, fmt('non-cached property %@ should be called 1x', [key])); }); });
StringPrototype.w = function () { return w(this); };
QUnit.test('\'one two three\'.w() with tabs', function() { deepEqual(w('one\ttwo three'), ['one', 'two', 'three']); if (Ember.EXTEND_PROTOTYPES) { deepEqual('one\ttwo three'.w(), ['one', 'two', 'three']); } });
QUnit.test('\'one two three\'.w() with extra spaces between words => [\'one\',\'two\',\'three\']', function() { deepEqual(w('one two three'), ['one', 'two', 'three']); if (Ember.EXTEND_PROTOTYPES) { deepEqual('one two three'.w(), ['one', 'two', 'three']); } });
QUnit.test('\'one two three\'.w() => [\'one\',\'two\',\'three\']', function() { deepEqual(w('one two three'), ['one', 'two', 'three']); if (Ember.EXTEND_PROTOTYPES) { deepEqual('one two three'.w(), ['one', 'two', 'three']); } });
QUnit.test("'one two three'.w() => ['one','two','three']", function() { deepEqual(w('one two three'), ['one','two','three']); if (Ember.EXTEND_PROTOTYPES) { deepEqual('one two three'.w(), ['one','two','three']); } });
test("'one two three'.w() with extra spaces between words => ['one','two','three']", function() { deepEqual(w('one two three'), ['one','two','three']); if (Ember.EXTEND_PROTOTYPES) { deepEqual('one two three'.w(), ['one','two','three']); } });