JS Bank Account test error

See here - Bank Account in JavaScript on Exercism

xtest("close already closed account throws error", () => {
  const account = new BankAccount();
  expect(() => {
    account.close();
  }).toThrow(ValueError);
});

xtest("open already opened account throws error", () => {
  const account = new BankAccount();
  account.open();
  expect(() => {
    account.open();
  }).toThrow(ValueError);
});

I’ve included the similar test for .open() because it shows the problem with the .close() test - the method is not called twice in the test. This is preventing me from completing the exercise :confused:

The test should instead be:

xtest("close already closed account throws error", () => {
  const account = new BankAccount();
  account.close(); // <- add this line
  expect(() => {
    account.close();
  }).toThrow(ValueError);
});

A new BankAccount object is not considered open until you call open().

There don’t seem to be any other tests that examine this. We have

  test('deposit into closed account throws error', () => {
    const account = new BankAccount();
    account.open();
    account.close();
    expect(() => {
      account.deposit(50);
    }).toThrow(ValueError);
  });

but not

  test('deposit into **never-opened** account throws error', () => {
    const account = new BankAccount();
    expect(() => {
      account.deposit(50);
    }).toThrow(ValueError);
  });
1 Like

Thank you, @glennj! You’re absolutely right, I had set myself up for failure by making the assumption (yep, I know what they say about assuming) that the account should be opened inside the BankAccount constructor. I removed that and everything is now working as intended :)

2 Likes

@junedev @SleeplessByte Are you open to a PR to help reduce this confusion?

1 Like

Yes. But this is a problem specced exercise so you probably want to add it there too.

Bank Account doesn’t have any canonical data. @Meatball put some together for the Python track (here) - but we have yet to PR it into problem specs. Happy to PR it, or have someone else do it, if it helps fix this issue for JS.

1 Like

Probably a good moment to make it canonical? The JS implementation is a bit shabby tbh, and @itsjustaaron is rightly running into trouble.

1 Like

This is in line with my comment here:

1 Like

My github search-fu is not strong. What tracks have implemented bank-account? I know there are some that use this exercise to look at concurrency and thread safety.

My foo is meager as well. But I did a brut search org-wide for bank-account and got these results.

So at least on the first page…

  • javascript
  • python
  • clojure
  • go
  • lfe
  • lua
  • elixir
  • tcl
  • haskell
  • c-sharp
  • c ++
  • erlang
  • kotlin
  • scala
  • java
  • f#
  • delphi
  • wasm
  • wren

I opened a pr on the problem spec repo with conical data, let me know if you have any suggestions of what could be changed/improved and if you feel like som tests are missing.

You can find the pr here: [Bank account]: Add canonical data by meatball133 · Pull Request #2192 · exercism/problem-specifications (github.com)

1 Like