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).

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

FYI this line doesn’t do anything. You’re just binding a value to a variable, which cannot fail.

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

This is a good idea for production, but not a good idea when at the “learn from a book” stage. You always should use the exact versions specified in the book unless you are sufficiently familiar with the subject matter to make the necessary changes.

In this specific case, the change is extremely minor, so it’s up to you. If you want to use latest you can, but you’ll want to do json_response(response, 200) instead of json_response(response, 400). My recommendation is to stick to the book versions while learning from the book. There are very few things different between the book version and the latest Absinthe version, but there are enough that it can confuse beginners. Go through the book till you have some comfort with it, then do your new project on the latest version.

Where Next?

Popular in Chat/Questions Top

meraj_enigma
Hey, What’s a good resource to learn Microservices in Elixir/Phoenix? Is there any book/docs/Github repos that I can refer to? Thanks, -M
New
pietrofxq
I’ve bought the following books: Programming Elixir 1.6 Programming Phoenix 1.4 Programming Ecto Functional Web Development with Elixir...
New
OmanF
In the attached screenshot (taken from an exercise in “Programming Elixir”) can be shown that BugReport is defined as a struct that, itse...
New
shansiddiqui94
Hello all, I recently did my first app in Phoenix and Liveview, many thanks to all the users who assisted me. I found that the tutorial ...
New
woohaaha
I’m coming from Ruby and Rails. I have read some Elixir and Phoenix books. They shed a lot of light about building applications in Elixir...
New
miguelsrrobo
hi i was wondering if it is necessary to learn erlang to learn elixir
New
asfand
Hi Everyone, I am a student and know basics of web development, used some php and ruby, but I am not an expert in any. I want to learn E...
New
New
dogweather
Can anyone recommend books/courses/videos that use real-world Elixir? E.g.: Idiomatic error handling design, whether it’s {ok/error, .....
New
Fl4m3Ph03n1x
Background I am trying to do the typical Ceaser cypher exercise in Elixir. The description of the exercise is as follows: Create an impl...
New

Other popular topics Top

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
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement