mardi 1 décembre 2020

How do you correctly test that an error is raised in Rails?

I'm testing an Interactor in Rails with assert_raise and I'm passing arguments to it that should not raise an error.

However, the assert_raise on that Interactor call doesnt fail, rendering a false positive.

VCR.use_cassette("crm.active_campaign.retrieve_contact_tags_for_contact.successful") do
  response = Crm::ListTags.call(adapter: @adapter, contact_id: contact_id)
  assert response.success? # assertion success
  assert_raise StandardError do
    Crm::ListTags.call(adapter: @adapter, contact_id: contact_id) # assertion should fail but doesn't (as if it were reaching the error)
  end
end

As you can see I'm passing the same arguments to both Interactor calls. The second one should fail because it should not reach the error that it expects to. However it doesnt.

@vue/text-utils mount returns CSSStyleDeclaration { ..., undefined: 'Somevalue' } for .style element

I have a component Space.vue:

<template>
  <div class="space" :style="{ perspective: '800px', perspectiveOrigin: x + '% ' + y + '%' }">
</template>

When I try to test:

test('it should match the snapshot', () => {
  const wrapper = mount(Space);
  console.log(wrapper.element.style);
});

I'm getting this:

CSSStyleDeclaration {
  _values: {},
 _importants: {},
 _length: 0,
 _onChange: [Function (anonymous)],
 undefined: '50% 50%'
}

Anybody had this? Wanna check values of particular styles values after some event triggering (mousemove to be specific);

React Testing keeps fetching getByText

I have been trying to Test my react code by putting some key word inside my todo list and then clearing the array when the testing clicks my clear button. But my test keeps failing. It says

● add todo

    expect(element).toHaveTextContent()

    Expected element to have text content:
      Go to coffee
    Received:
      AddClear

      15 |   fireEvent.click(button);
      16 | 
    > 17 |   expect(container).toHaveTextContent('Go to coffee');
         |                     ^
      18 | 
      19 |  const clearbutton = getByText('Clear');
      20 |  fireEvent.click(clearbutton);

Here is my code

import React, { useState } from 'react';

function App() {
  const [todo, setTodo] = useState({desc:'', date:''});
const [todos, setTodos] = useState([]);
  
const addTodo = (event) =>  {
  event.preventDefault();
  setTodos([...todos, todo]);
  setTodo({ desc: '' , date:'' });
}
const inputChanged = (e) => {
  setTodo({...todo, [e.target.name]: e.target.value});
}
const clearAll = () => {
  setTodo([]);
}
return (
  <div className="App">
  <input type="text"placeholder="Date"name="date"
  value={todo.date} onChange={inputChanged}/>
  <input type="text"placeholder="Description"
  name="desc"value={todo.desc} onChange={inputChanged}/>
  <button onClick={addTodo}>Add</button>
  <button onClick={clearAll}>Clear</button>
  </div>
  );
}

export default App;

Testing code.

import React from 'react';
import App from './App.js'
import{ fireEvent, render} from'@testing-library/react';
import '@testing-library/jest-dom/extend-expect'

test('add todo', () =>  {
  const { container, getByText, getByPlaceholderText}= render(<App/>);
  const desc = getByPlaceholderText('Description');
  fireEvent.change(desc, { target:{ value:'Go to coffee'} })

  const date= getByPlaceholderText('Date');
  fireEvent.change(date, { target:{ value:'29.11.2019'} })

  const button= getByText('Add');
  fireEvent.click(button);

  expect(container).toHaveTextContent('Go to coffee');
  
 const clearbutton = getByText('Clear');
 fireEvent.click(clearbutton);
 expect(container).not.toHaveTextContent('Go to coffee');

})

Does anyone know why it keeps fetching the word in getByText?? And how I can solve them..?

benchmark existing test

I have a test which takes too much time to execute. I would like to benchmark it and see where are the main bottle necks. I understood I need to make:

func BenchmarkMyTest(b *testing.B) {
// use b.N somewhere
}

and run it with go test -bench=. but I wanted to benchmark existing test, can I wrap it somehow? What will be parameter t *testing.T I'll pass to?

Fatal: unable to get current working directory: Operation not permitted

New to Node.js and JavaScript (my environment is currently set-up for RoR); I run into the following error described in the title when trying to test code by installing project dependencies npm i (listed here: https://www.npmjs.com/package/doubleratchet). I think at some point I need to do run node index.js but am unsure. When I look up node -v command is not found.

For additional reference and context, the code I am trying to test for functionality is here, which is a JavaScript executable script on the command line: https://github.com/Itp-test/double-ratchet-test

Essentially, I'm trying to check if the 1) Send (arguments: message to send) 2) Receive (arguments: the encrypted message) 3) Also, arguments are whether you're person 1 or 2, then sending will output the encrypted message and receiving outputs the decrypted message

If anyone can help point me in the right direction as to how I can go about testing this command line script that would be greatly appreciated. Thank you.

online IDE for java [closed]

I want to upload my java programs in an online IDE so my teacher and friends can test it... My program is a math project for school. I used JDoodle and Codiva before but the problem is that others can see the code and my teacher asked me to find another (if any) online java IDE which shows the code only to the admin and just compiles it for the others. It needs to get an input from the user. Do you have any suggestions?

lundi 30 novembre 2020

Some Typescript test files fail to execute with Mocha and ts-node - "unknown option"

I've been testing my prject for some time with mocha and ts-node with no issues. lately some of the test files started failing on execution returning the following:

error: unknown option '--require'

same result with -r

i'm using the same execution format for all files:

node_modules/mocha/bin/mocha --require ts-node/register ***path to test file***

some files execute correctly and some return the said error.

any thoughts?