Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
jasmine test doesn't see object results while the function return object

i have the following simple JS function that return an object

async create(o: Order): Promise<Order> {
try {
  const conn = await client.connect();
  const checkActiveQuery = "SELECT id FROM orders WHERE userId = $1 AND currentStatus = $2;";
  const checkActiveQueryRes = await conn.query(checkActiveQuery, [o.userId, o.currentStatus,]); 
  if (checkActiveQueryRes.rows[0]) {
    console.log('True Already Existed Active order')
    conn.release();
    throw new Error('an active order for this user already exists');
  } else {
    console.log('started to failllllll here')
    const sql = 'INSERT INTO orders (userId, currentStatus) VALUES ($1, $2) RETURNING *;';
    const result = await conn.query(sql, [o.userId, o.currentStatus]);
    conn.release();
    const order = result.rows[0];
    console.log('new order has: ' + order)
    console.log(order)
    console.log(order.id)
    return (order);
  }
} catch (err) {
  throw new Error(`Cannot create order: ${err}`);
}}

while i am trying to test it using jasmine specs as following

  it('create method should add an order', async () => {
    const order: Order = await orderStore.create({userId: 1, currentStatus: 'active'})
    expect(order).toEqual({id: 1, userId: 1, currentStatus: 'active',})
  })

i got the following console error from the spec itself as if it doesn't see results

Order model method create method should add an order

  - Expected object to have properties
      userId: 1
      currentStatus: 'active'
  Expected object not to have properties
      userid: '1'
      currentstatus: 'active'

Wile i made the function to return three kinds of result.rows[0] object as it return here in console

new order has: [object Object] ==> order object var in console.log('new or...' + order)
{ id: 1, userid: null, currentstatus: null } ==> order object in console.log(order)
1 ==> picked up order.id

what's the difference between the 1st two lines of order variable and why not explicitly has the same properties shown in console and what to do to make this test success please any help, i would be grateful to you

console results

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!