wolfiton

wolfiton

Test error case in wormwood

Hi everyone,

Can’t find any error map in wormwood

My test works but I can’t test an error

describe "GetMenuItems.gql == error" do
    test "Should return error Menu items (0 of them)" do
      result = query_gql(variables: %{"matching" => "123"})
      IO.inspect(result)
      assert {:ok, %{data: %{"MenuItems" => menu_items}}} = result

      IO.inspect(menu_items)

      assert length(menu_items) == 0
    end
  end

This all I have

{:ok, %{data: %{"MenuItems" => []}}}

Am I missing something?

Thanks

Most Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

I’m happy to keep helping you, but there are some Elixir basics here you seem to be struggling with that are making this a lot harder than it needs to be. Look carefully at the error message. Look at the exact data types between what you have what you are asserting on the left, and what the value of result is on the right. In particular, pay attention to what values are strings and what values are atoms.

Based on the content of your error messages, it looks like you’re working through the Absinthe book. This is a great way to learn absinthe. However, since you’re very new to this, I don’t think it’s a good idea to try to BOTH work through a new book AND utilize a testing library that isn’t used in the book. There are subtle but important differences between how wormwood tests work and how regular ExUnit test work, and those differences will only increase as you go further into the book and start handling things like authentication headers. I would ditch wormwood for now, and revisit it later after you have a solid grasp of how Absinthe and Elixir testing works.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Why should that return an error? 0 results isn’t an error. Additionally, a graphql query will only return an error if there is a syntax / validation issue with the query itself, or if you return an error from the resolver. If you aren’t doing that, it won’t error.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

You didn’t pass in the same value. You passed in "123" (a string), but the wormwood example uses 123 (an integer).

Where Next?

Popular in Chat/Questions Top

nur
https://e.planaria.network Build a NoSQL DB, Build a Relational SQL Database, Build a Graph Database, Build a File System, Build a Bitc...
New
aswinmohanme
I recently finished the Udemy course on Elixir and Phoenix and I am thinking about using it for the next project. But I am stuck as how t...
New
marciol
Hey, I have very restricted resources and time so I’m trying to understand the best way to learn Liveview in terms of cost/time. The Pra...
New
boddhisattva
Greetings everyone, At my current workplace we’re evaluating different ways of building a microservices architecture for some parts rela...
New
Fl4m3Ph03n1x
GenStage and Flow resources? I have been hearing about GenStage and Flow, a tool built upon it, for quite some time. I understand it allo...
New
wallyfoo
Long story short, I have a real world need to create a view for hooking up a shipping terminal to live data, but because of some early ar...
New
pdgonzalez872
Hi! In my quest of becoming the best Elixir dev I can be, I saw one aspect in my career that I’d like to improve upon. This is language...
New
koen_vb
Hi, I was looking for a pointer of how I could most easily start with phoenix regarding deploying it to something like linode or google c...
New
maqbool
what books/Resources do you recommend to learn about distributed system(theory)?
New
Sujit
Hi Team From the title, I am entirely new to programming and i am interested in learning elixir but not sure where to start. Can someone...
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement