package opium-testing
Testing library for Opium
Install
Dune Dependency
Authors
Maintainers
Sources
opium-0.20.0.tbz
sha256=326b91866de90baf535f8b7d4b2ff23e39d952e573c04b3c13f1054b59ff2fb6
sha512=59b83e7c8fe5f7ae328fb7f2343fe5b8fb735e8f6ee263cfd6c75bb179688ef7cf2b4586b35a2231ed3f3c1ada543021b7a4759326ae095eb77a5f38b9fa3a8a
doc/index.html
Opium Testing
opium-testing
provides helpers to easily test Opium applications with Alcotest.
Installation
To install opium-testing
, you can add it to your dune-project
's package stanza:
(package (name my_app) (depends (ocaml (>= 4.08)) (dune (>= 2.0)) rock (alcotest :with-test) (alcotest-lwt :with-test) (opium-testing :with-test)))
And let Dune generate the Opam file for you. Or you can add it directly to your .opam
file:
depends: [ "alcotest" {with-test} "alcotest-lwt" {with-test} "opium-testing" {with-test} ]
Usage
Here's a sample unit test that tests if the response is the one expected.
open Alcotest
open Lwt.Syntax
open Rock
open Opium_testing
let test_case n f = Alcotest_lwt.test_case n `Quick (fun _switch () -> f ())
let handle_request = handle_request My_app.app
let suite =
[ ( "POST /create-user"
, [ test_case "redirects to show when data is valid" (fun () ->
let req =
Request.of_json
~body:(`Assoc [ "name", `String "Tom" ])
"/create-user"
`POST
in
let+ res = handle_request req in
check_status `Found res.status)
; test_case "renders errors when data is invalid" (fun () ->
let req =
Request.of_json
~body:(`Assoc [ "invalid-key", `String "invald-value" ])
"/create-user"
`POST
in
let+ res = handle_request req in
check_status `Bad_request res.status;
check_body_contains "Invalid data" res.body)
] )
]
;;
let () = Lwt_main.run @@ Alcotest_lwt.run "User Handler" suite
API documentation
Opium_testing
This module provides helpers to easily test Opium applications with Alcotest.
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
On This Page