Skip to content

Commit

Permalink
Add a test for some of the basic rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
lavigneer committed Nov 10, 2024
1 parent 68b8ce2 commit 3a94eec
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package autorefresh_test

import (
"bytes"
"html/template"
"regexp"
"strings"
"testing"

autorefresh "github.com/lavigneer/browser-autorefresh"
)

func TestTemplate(t *testing.T) {

Check failure on line 13 in main_test.go

View workflow job for this annotation

GitHub Actions / build

Function TestTemplate missing the call to method parallel (paralleltest)
testTemplate := template.New("main")

autorefresh.New(testTemplate, "__test_path__", 250)

Check failure on line 16 in main_test.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `autorefresh.New` is not checked (errcheck)
var b bytes.Buffer
testTemplate.Execute(&b, nil)

Check failure on line 18 in main_test.go

View workflow job for this annotation

GitHub Actions / build

Error return value of `testTemplate.Execute` is not checked (errcheck)
if !strings.Contains(b.String(), "new WebSocket(\"__test_path__\")") {
t.Fatalf("Did not insert path correctly for the websocket. Rendered %s", b.String())
}
if !regexp.MustCompile("setTimeout.*250").MatchString(b.String()) {
t.Fatalf("Did not insert timeout correctly for the websocket. Rendered %s", b.String())
}
}

0 comments on commit 3a94eec

Please sign in to comment.