Skip to content

Anthony Mclean Assignment #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

unrulytony
Copy link

No description provided.

Copy link
Contributor

@dimitriharding dimitriharding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see the review changes.

@@ -0,0 +1,76 @@
describe('06', () => {

// Tip: Use setTimeout to delay the execution of marking
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few things that were wrong with this submission so I decided to add the solution here and I will also outline what happened, although your test passed.

// Solution
describe('06', () => {
  // Tip: Use setTimeout to delay the execution of marking

  const listOfPapers = [
    {
      subject: 'Maths',
      wasSubmitted: true,
      markPaper: () => {
        return new Promise((resolve, reject) => {
          setTimeout(() => {
            resolve('Maths paper marked');
          }, 2000);
        });
        // add a promise here that resolves after 2 seconds
        // and print "Maths paper marked"
      },
    },
    {
      subject: 'Geology',
      wasSubmitted: true,
      markPaper: () => {
        return new Promise((resolve, reject) => {
          setTimeout(() => {
            resolve('Geology paper marked');
          }, 2000);
        });
        // add a promise here that resolves after 2 seconds
        // and print "Geology paper marked"
      },
    },
    {
      subject: 'Social Studies',
      wasSubmitted: false,
      markPaper: () => {
        return new Promise((resolve, reject) => {
          setTimeout(() => {
            resolve('Social Studies paper marked');
          }, 2000);
        });
        // add a promise here that resolves after 2 seconds
        // and print "Social Studies paper marked"
      },
    },
  ];

  it('Check if a paper was submitted, and if yes, wait for it to be marked', async () => {
    const spyOnLog = vi.spyOn(console, 'log');

    for (const paper of listOfPapers) {
      if (paper.wasSubmitted === true) {
        await paper.markPaper().then((result) => {
            console.log(result)
        })
      }
    }

    expect(spyOnLog).toHaveBeenCalledWith('Maths paper marked');
    expect(spyOnLog).toHaveBeenCalledWith('Geology paper marked');
    expect(spyOnLog).not.toHaveBeenCalledWith('Social Studies paper marked');
    expect(listOfPapers[0].markPaper()).toBeInstanceOf(Promise);
    expect(listOfPapers[1].markPaper()).toBeInstanceOf(Promise);
    expect(listOfPapers[2].markPaper()).toBeInstanceOf(Promise);
  });
});

subject: "Maths",
wasSubmitted: true,
markPaper: () => {
const promise = new Promise((resolve,reject) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed to return the promise here rather than create a variable for the promise.

Suggested change
const promise = new Promise((resolve,reject) => {
return new Promise((resolve,reject) => {

// }
for await (const paper of listOfPapers){
if(paper.wasSubmitted === true){
return paper.markPaper()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what case the test to pass without actually passing.

Since you used the return statement in the for loop, the markPaper function was returned to the test and since there was no error the test passed before getting to the test cases.

Ideally, the promise needed to be resolved using the await keyword, and printing the results to the console.

Suggested change
return paper.markPaper()
if (paper.wasSubmitted === true) {
await paper.markPaper().then((result) => {
console.log(result)
})
}

constructor (wheels,bodyType){
this.wheels = wheels;
this.bodyType = bodyType;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since classes are meant to reduce duplicate code, the expectation was that you define the whatIsMyName method on the parent class "Vehicle" and then all child classes would inherit from it, so you wouldn't have to define the same method on all child classes.

@unrulytony
Copy link
Author

unrulytony commented Nov 1, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants