Bomber
Bomber

Reputation: 10947

object literal - a different key must be given explicitly

Helllo, I am slowly working through the ES6 code at http://es6katas.org/.

I'm stuck on the this piece of code:

const func = () => func;

it('a different key must be given explicitly, just like before ES6', () => {
  const short = {func};
  assert.deepEqual(short, {otherKey: func});
});

How can I get my test to pass by using an explicit key? I'm not allowed to change the assertion, just the other code.

Upvotes: 0

Views: 79

Answers (2)

T.J. Crowder
T.J. Crowder

Reputation: 1074028

If we have to keep the assertion unchanged, then you need to update the code so the "other key" given matches the name of the variable used in short.

For instance:

const func = () => func;

it('a different key must be given explicitly, just like before ES6', () => {
  const otherKey = func;
  const short = {otherKey};
  assert.deepEqual(short, {otherKey: func});
});

Upvotes: 0

CupawnTae
CupawnTae

Reputation: 14580

The purpose of this exercise is to demonstrate that if you want to use a key that doesn't match the name of the variable holding the value, you need to give the key explicitly, just like you would have before ES6.

It's a pretty trivial exercise, and the variable name short makes the resulting code look a bit odd, but it's simply:

it('a different key must be given explicitly, just like before ES6', () => {
  const short = {otherKey: func};
  assert.deepEqual(short, {otherKey: func});
});

Upvotes: 1

Related Questions